Topic: dependant template parameters


Author: Entwicklung@reico.de (Olaf Krzikalla)
Date: Thu, 16 Jan 2003 19:03:14 +0000 (UTC)
Raw View
Hi,

in the german C++-newsgroup the following problem popped up (once
again):

template<typename T, T C>
class A { /*...*/ };

Altough T could be deduced simply by looking at the type of C, it isn't
done by the current language. A solution was proposed by Dietmar Kuehl:

http://groups.google.com/groups?hl=de&lr=&ie=UTF-8&oe=UTF-8&selm=3C7715EF.5020001%40yahoo.com

I came up with another idea: allow some form of meta templates:

template<typename T>
template<T C>
class A { /*...*/ };

Here the template argument list itself is templatized. The type deducing
mechanism would work like it works with function templates.
E.g. instead of

template<typename S, typename T, S (*FUNC)(T)>
class A { /*...*/ };

double foo (int);

typedef A<double, int, &foo> A_foo;

you could write:

template<typename S, typename T>
template<S (*FUNC)(T)>
class A { /*...*/ };

double foo (int);

typedef A<&foo> A_foo;

Explicit specialization must still be possible:

double foo (int);
int foo (double);

typedef A<double, int><&foo> A_foo_di;  //int -> double

This also might be useful whenever you have to generate templates
automatically (actually this struggles my mind, but I haven't found an
example yet).
Is there any other work related to this issue? And what's your opinion?


Best regards
Olaf Krzikalla

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]