digitalmars.D - Template argument type auto detect
- nail (25/25) Jan 21 2005 Hello all,
- Lionello Lunesu (3/3) Jan 21 2005 I think you need to 'instanciate' the template with a "!", so foo!() or ...
- J Anderson (5/35) Jan 21 2005 //Should be (something like)
- nail (1/2) Jan 21 2005 Why? What is the hindrance?
- J Anderson (10/16) Jan 21 2005 1) Walter's against it.
Hello all, Who can say why impossible to do following class Class { template foo(T) { bit foo(T a, T b) { return a == b; } } } int main ( char [] [] args ) { int x, y; Class c; c.foo(x, y); // call return 0; } C:/dmd/bin/dmd -I. -IC:\dmd\src\phobos -Isrc -c -ofexamples\src\test\test.obj examples\src\test\test.d examples\src\test\test.d(124): c.foo is not a declaration examples\src\test\test.d(124): function expected before (), not 'int' Why compiler can't replase call line with c.foo!(int)(x, y) automaticly like in C++?
Jan 21 2005
I think you need to 'instanciate' the template with a "!", so foo!() or so. Dunno, never done it before. L.
Jan 21 2005
nail wrote:Hello all, Who can say why impossible to do following class Class {//Templates are like a class/namespace in Dtemplate foo(T) { bit foo(T a, T b) { return a == b; } } } int main ( char [] [] args ) { int x, y;Class c;//Should be (something like) Class.foo!(int) c = new Class.foo!(int)();c.foo(x, y); // callThere is no automatic type induction in D.return 0; } C:/dmd/bin/dmd -I. -IC:\dmd\src\phobos -Isrc -c -ofexamples\src\test\test.obj examples\src\test\test.d examples\src\test\test.d(124): c.foo is not a declaration examples\src\test\test.d(124): function expected before (), not 'int' Why compiler can't replase call line with c.foo!(int)(x, y) automaticly like in C++?
Jan 21 2005
There is no automatic type induction in D.Why? What is the hindrance?
Jan 21 2005
nail wrote:1) Walter's against it. 2) It makes the compiler harder to write. 3) There are apparently some un-expected side-effects. As for me, I would love to have some form of automatic induction for templates. -- -Anderson: http://badmama.com.au/~anderson/ -- -Anderson: http://badmama.com.au/~anderson/There is no automatic type induction in D.Why? What is the hindrance?
Jan 21 2005