digitalmars.D - Deduction of Template Value Parameters
- gg (14/14) Nov 02 2010 Why we cant deduce value parameter of templates:
- bearophile (7/17) Nov 02 2010 You are doing it wrong. Try:
- gg (24/30) Nov 02 2010 Sorry,i must check before posting, I tried to reduce to a simple test ca...
- bearophile (4/5) Nov 03 2010 It may be a compiler bug. If confirmed you (or someone else) may put it ...
- Steven Schveighoffer (7/24) Nov 03 2010 I think there is a way to do this, but I think you have to include the
- Steven Schveighoffer (5/29) Nov 03 2010 Hm... that should have been:
Why we cant deduce value parameter of templates: void caracterize(uint m)(pp!(m)){ } class pp(uint m){ } void main(){ caracterize(pp!5); } fails with dmd chap.d chap.d(8): Error: template chap.caracterize(uint m) does not match any function template declaration chap.d(8): Error: template chap.caracterize(uint m) cannot deduce template function from argument types !()(void) Or at least of a way to extract template instantiation information would be useful. Or it is needed to do it the long way
Nov 02 2010
gg:Why we cant deduce value parameter of templates: void caracterize(uint m)(pp!(m)){ } class pp(uint m){ } void main(){ caracterize(pp!5); }You are doing it wrong. Try: caracterize(new pp!5U()); You need to build the class instance with new, and if you want an uint you need to add a U. You may also ask similar questions in the D.learn group. Bye, bearophile
Nov 02 2010
You need to build the class instance with new, and if you want an uint you need to add a U. You may also ask similar questions in the D.learn group. Bye, bearophileSorry,i must check before posting, I tried to reduce to a simple test case al long code. This is THE an actual confusion: FAILS class Matrix (Tx,uint x, uint y){ } void tes(T,uint x,uint y)(Matrix!(T,x,y) x){ } void main(){ auto g = new Matrix!(double,5,4)();//Here should be the error.! tes(g);// WHY fails here? } fails Error: cannot implicitly convert expression (g) of type chap.Matrix!(4).Matrix to chap.Matrix!(x).Matrix WORKS class Matrix (Tx,uint x, uint y){ } void tes(T,uint x,uint y)(Matrix!(T,x,y) x){ } void main(){ auto g = new Matrix!(double,5u,4u)(); tes(g); } The actual question why 5 and 4 and 5u and 4u are accepted in template instantiation but only one is valid
Nov 02 2010
gg:The actual question why 5 and 4 and 5u and 4u are accepted in template instantiation but only one is validIt may be a compiler bug. If confirmed you (or someone else) may put it into Bugzilla. Bye, bearophile
Nov 03 2010
On Tue, 02 Nov 2010 21:56:44 -0400, gg <noreply now.pl> wrote:Why we cant deduce value parameter of templates: void caracterize(uint m)(pp!(m)){ } class pp(uint m){ } void main(){ caracterize(pp!5); } fails with dmd chap.d chap.d(8): Error: template chap.caracterize(uint m) does not match any function template declaration chap.d(8): Error: template chap.caracterize(uint m) cannot deduce template function from argument types !()(void) Or at least of a way to extract template instantiation information would be useful. Or it is needed to do it the long wayI think there is a way to do this, but I think you have to include the pp!(m) parameter, something like: caracterize(m, T : pp!m)(pp!(m) arg) Look through phobos' source, you will probably find someone else has solved the problem. -Steve
Nov 03 2010
On Wed, 03 Nov 2010 10:19:28 -0400, Steven Schveighoffer <schveiguy yahoo.com> wrote:On Tue, 02 Nov 2010 21:56:44 -0400, gg <noreply now.pl> wrote:Hm... that should have been: caracterize(m, T : pp!m)(T arg) -SteveWhy we cant deduce value parameter of templates: void caracterize(uint m)(pp!(m)){ } class pp(uint m){ } void main(){ caracterize(pp!5); } fails with dmd chap.d chap.d(8): Error: template chap.caracterize(uint m) does not match any function template declaration chap.d(8): Error: template chap.caracterize(uint m) cannot deduce template function from argument types !()(void) Or at least of a way to extract template instantiation information would be useful. Or it is needed to do it the long wayI think there is a way to do this, but I think you have to include the pp!(m) parameter, something like: caracterize(m, T : pp!m)(pp!(m) arg)
Nov 03 2010