Re: Template name as template parameter (or something like that)
On 17 Nov., 16:32, Pete Becker <p...@versatilecoding.com> wrote:
template <template<class, class> class maptype, class keytype, class
valuetype> ...
By the way, hash_map almost certainly won't work here, because it
probably takes more then two template arguments, with all but the first
two having defaults. Welcome to the wonderful world of template
template parameters.
G++ seems to like the following code even with -Wall and -pedantic. In
the function "fun" the template class D ist instantiated with
"SuperMap" as a template template parameter that has a third template
parameter with a default (T3 = int).
template<typename KEY, typename MTYPE, typename T3 = int>
class SuperMap {};
template< template<typename,typename> class MAP,
typename K, typename V>
class D {
MAP<K,V> t1;
MAP<V,K> t2;
};
void fun() {
// D wants: template<class,class>
// it gets: template<class,class,class=int>
D<SuperMap,int,int> d();
}
Is this really not supported by the C++ standard officially?
Incidentally, a more verbose approach is used in the standard library
(whose interface pre-dated template template parameters). Use your
original definition, and instantiate it with the right type:
double_map<hash_map<string, int>, string, int> mymap;
In that case you need some kind of "rebinding" functionality
(MAPTYPE::rebind<VAL,KEY>::type) to make it work. --- or just another
template parameter for the 2nd map type.
Cheers!
SG