Thread overview
non-static member-template-function proposal
Jan 16, 2004
Matthias Becker
Jan 17, 2004
Matthias Becker
Jan 17, 2004
Andy Friesen
Jan 18, 2004
Matthew
January 16, 2004
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.


January 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 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.
>
>


January 17, 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.


January 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
January 18, 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...
> >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.
>
>