digitalmars.D - Overloading template functions
- Sean Kelly (28/28) Jul 29 2005 I should have expected this, but it took me a bit by surprise:
- Manfred Nowak (9/12) Jul 30 2005 In essence you want to be allowed to split the contents of currently
- Sean Kelly (25/36) Jul 30 2005 Thing is, the compiler already doesn't complain that I have two template
- Sean Kelly (8/21) Jul 30 2005 I'm going to take this back. I like being able to do things like this i...
- Sean Kelly (5/28) Jul 31 2005 Oops. In paring down my test case the error changed. The original one
I should have expected this, but it took me a bit by surprise: Compiling gives the error: test.d(10): template test.fn(T) conflicts with test.fn(T) at test.d(1) I can get around this by moving both functions into the same template block and calling the function as fn!(int).fn(1) but this is a bit unwieldy. I would love it if we had some sort of abbreviated template function syntax that allowed them to be overloaded properly and called via the compact form. Sean
Jul 29 2005
Sean Kelly <sean f4.ca> wrote: [...]I would love it if we had some sort of abbreviated template function syntax that allowed them to be overloaded properly and called via the compact form.In essence you want to be allowed to split the contents of currently only one allowed template body into several body fragments. Surely the compiler can be adviced to recombine this fragments to only onje template body. But what rules should the compiler follow by this recombination and what other possible extensions will conflict with such fragmentation? -manfred
Jul 30 2005
In article <dcfei8$bvh$1 digitaldaemon.com>, Manfred Nowak says...Sean Kelly <sean f4.ca> wrote: [...]Thing is, the compiler already doesn't complain that I have two template functions with the same name and parameter scope (ie. two of 'template fn(T)'). In practice it seems like it just instantiates the first applicable one rather than checking further. What I would like it to do is evaluate all applicable templates in lookup scope. If it is a function call then the contents could be considered for overload resolution. If it is something else then the compiler should likely display an error about multiply defined symbols. While we're on the topic, I would also like it if template contents were only instantiated as needed. ie. In C++, the above compiles and runs just fine--fn2 is never instantiated because it is never called. In D, the entire template contents are instantiated and this will fail on the static assert during compilation. Basically, I want the behavior of C++ templates but the flexibility of D templates. I realize that this may require template handling to be a bit more complex than Walter would like, but it never hurts to ask :) SeanI would love it if we had some sort of abbreviated template function syntax that allowed them to be overloaded properly and called via the compact form.In essence you want to be allowed to split the contents of currently only one allowed template body into several body fragments. Surely the compiler can be adviced to recombine this fragments to only onje template body. But what rules should the compiler follow by this recombination and what other possible extensions will conflict with such fragmentation?
Jul 30 2005
In article <dcg9l0$113i$1 digitaldaemon.com>, Sean Kelly says...While we're on the topic, I would also like it if template contents were only instantiated as needed. ie. In C++, the above compiles and runs just fine--fn2 is never instantiated because it is never called. In D, the entire template contents are instantiated and this will fail on the static assert during compilation.I'm going to take this back. I like being able to do things like this in D: and runs somewhat contrary to what I asked for above. Unless this rule could only apply to member functions, which seems a bit arbitrary. Sean
Jul 30 2005
In article <dcetge$2t8f$1 digitaldaemon.com>, Sean Kelly says...I should have expected this, but it took me a bit by surprise: Compiling gives the error: test.d(10): template test.fn(T) conflicts with test.fn(T) at test.d(1)Oops. In paring down my test case the error changed. The original one complained that I'd passed the wrong number of arguments to fn(). I'm trying to reproduce the problem again now. Sean
Jul 31 2005