Partial template function specialization

Peter Alexander peter.alexander.au at gmail.com
Wed Aug 19 17:47:31 PDT 2009


Hey all,

I'm considering learning D at the moment, and one thing that has bothered me in C++ is the lack of partial template function specializations. For example, you can create something like this:

template <class Field, class V>
const Field norm(const V& v);

and you can specialize it:

template <>
const double norm(const double& d)
{ return d < 0.0 ? -d : d; }

but you can't partially specialize it:

template <class Field>
const Field norm(const Vector3<Field>& v)
{ /* return sqrt( ... ) */ }

Unless I'm mistaken...

Also, while I'm here. Does D have any macro support? I know it doesn't have pre-processor macros, but something like Nemerle's macros would be really, really nice.

Thanks in advance.


More information about the Digitalmars-d-learn mailing list