www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Template alias as template specialisation not recognized.

reply Paul <paultjeadriaanse gmail.com> writes:
I'm having issues when trying to use a template alias as a 
template specialisation.
When using the following:
 alias Vec(uint size, Type) = Mat!(size, 1, Type);
 void setUniform(V : Vec!(L, bool), int L)(string name, V value) 
 {...}
 Vec!(4, bool) a;
 setUniform("test", a);
I get the following error:
 template `shader.Shader.setUniform` cannot deduce function from 
 argument types `!()(string, Mat!(4u, 1u, bool))`, candidates 
 are:DUB
shader.d(43, 7): `setUniform(V : Vec!(L, bool), uint L)(string name, V value)` Meanwhile, when using the following, I have no issues:
 void setUniform(V : Mat!(L, 1, bool), int L)(string name, V 
 value) {}
Jan 15 2021
next sibling parent reply Paul Backus <snarwin gmail.com> writes:
On Saturday, 16 January 2021 at 01:21:24 UTC, Paul wrote:
 I'm having issues when trying to use a template alias as a 
 template specialisation.
 When using the following:
 alias Vec(uint size, Type) = Mat!(size, 1, Type);
 void setUniform(V : Vec!(L, bool), int L)(string name, V 
 value) {...}
 Vec!(4, bool) a;
 setUniform("test", a);
I get the following error:
 template `shader.Shader.setUniform` cannot deduce function 
 from argument types `!()(string, Mat!(4u, 1u, bool))`, 
 candidates are:DUB
shader.d(43, 7): `setUniform(V : Vec!(L, bool), uint L)(string name, V value)` Meanwhile, when using the following, I have no issues:
 void setUniform(V : Mat!(L, 1, bool), int L)(string name, V 
 value) {}
You have encountered issue 1807: https://issues.dlang.org/show_bug.cgi?id=1807 The easiest way to work around it that I know of is to change `Vec` from an alias into a struct: struct Vec(uint size_, Type) { Mat!(size, 1, Type) payload; alias payload this; }
Jan 15 2021
parent Paul <paultjeadriaanse gmail.com> writes:
On Saturday, 16 January 2021 at 01:38:38 UTC, Paul Backus wrote:
 You have encountered issue 1807:

 https://issues.dlang.org/show_bug.cgi?id=1807
Ah I see, thank you, sad to see several DIP's I'd be interested in are postponed :( Thanks for the workaround hint, I'll probably be using that.
Jan 15 2021
prev sibling parent Basile B. <b2.temp gmx.com> writes:
On Saturday, 16 January 2021 at 01:21:24 UTC, Paul wrote:
 I'm having issues when trying to use a template alias as a 
 template specialisation.
 When using the following:
 alias Vec(uint size, Type) = Mat!(size, 1, Type);
 void setUniform(V : Vec!(L, bool), int L)(string name, V 
 value) {...}
 Vec!(4, bool) a;
 setUniform("test", a);
I get the following error:
 template `shader.Shader.setUniform` cannot deduce function 
 from argument types `!()(string, Mat!(4u, 1u, bool))`, 
 candidates are:DUB
shader.d(43, 7): `setUniform(V : Vec!(L, bool), uint L)(string name, V value)` Meanwhile, when using the following, I have no issues:
 void setUniform(V : Mat!(L, 1, bool), int L)(string name, V 
 value) {}
In this case you can use a const template parameter: alias Vec(uint size, Type, const uint length = 1) = Mat!(size, length, Type); Although this is not a generic workaround for the issue mentioned.
Jan 15 2021