D - non-static member-template-function proposal
- Matthias Becker (5/5) Jan 16 2004 One of the last features I realy miss in D are non-static
- Achilleas Margaritis (15/20) Jan 16 2004 Yes, indeed. Template methods are very important. For example, in C++, ...
- Matthias Becker (21/25) Jan 17 2004 Imagine this:
- Andy Friesen (4/14) Jan 17 2004 So how about if all template methods had to be either static or final?
- Matthew (10/35) Jan 17 2004 Maybe I'm having a thick day, but I don't see the problem. Can you
One of the last features I realy miss in D are non-static member-template-function. I think they aren't there because it's very hard or nearly impossible to make membertemplate-functions virtual (virtual in terms of C++). So I suggest to implement them as non-virtual methods. It can't be very hard to implement them this way, but they would be very usefull.
Jan 16 2004
Yes, indeed. Template methods are very important. For example, in C++, I have made a Variant class which uses template methods to hold any type of variable. In the template method, a template class that holds the variable is created. I use the Variant class for moving around data without knowing their data type, even from DLLs. boost::any also uses this (I think!!!). Why doing virtual template methods are hard ? I don't buy it. A template is simply a parameterized function, right ? so, if the subclasses overloads the method like it is (that means, as a template), then all instantiations are virtual. "Matthias Becker" <Matthias_member pathlink.com> wrote in message news:bu8h1u$3jl$1 digitaldaemon.com...One of the last features I realy miss in D are non-static member-template-function. I think they aren't there because it's very hardornearly impossible to make membertemplate-functions virtual (virtual interms ofC++). So I suggest to implement them as non-virtual methods. It can't beveryhard to implement them this way, but they would be very usefull.
Jan 16 2004
Why doing virtual template methods are hard ? I don't buy it. A template is simply a parameterized function, right ? so, if the subclasses overloads the method like it is (that means, as a template), then all instantiations are virtual.Imagine this: class Base { template <typename T> // c++-style pseudocode virtual void foo (T x) { ... } }; class DerivedA : public Base { template <typename T> void foo (T x) { ... } }; class DerivedB : public Base { template <typename T> void foo (T x) { ... } }; Base * foo = new DerivedA; foo->foo(22); // when the compiler sees this it has to add an entry to the VMT of Base, as well as to DerivedA which is obvious, but what about DerivedB? it isn't involved here, but anyway it is derived from Base, so it's VMT needs an entry for this method.
Jan 17 2004
Matthias Becker wrote:Imagine this: [...] foo->foo(22); // when the compiler sees this it has to add an entry to the VMT of Base, as well as to DerivedA which is obvious, but what about DerivedB? it isn't involved here, but anyway it is derived from Base, so it's VMT needs an entry for this method.So how about if all template methods had to be either static or final? No vtable entry required, right? -- andy
Jan 17 2004
Maybe I'm having a thick day, but I don't see the problem. Can you re-explain? :) "Matthias Becker" <Matthias_member pathlink.com> wrote in message news:bubbsm$1si9$1 digitaldaemon.com...isWhy doing virtual template methods are hard ? I don't buy it. A templatethesimply a parameterized function, right ? so, if the subclasses overloadsaremethod like it is (that means, as a template), then all instantiationsVMTvirtual.Imagine this: class Base { template <typename T> // c++-style pseudocode virtual void foo (T x) { ... } }; class DerivedA : public Base { template <typename T> void foo (T x) { ... } }; class DerivedB : public Base { template <typename T> void foo (T x) { ... } }; Base * foo = new DerivedA; foo->foo(22); // when the compiler sees this it has to add an entry to theof Base, as well as to DerivedA which is obvious, but what about DerivedB?itisn't involved here, but anyway it is derived from Base, so it's VMT needsanentry for this method.
Jan 17 2004