Re: Is there a typedef or a using-declaration equivalent for
templates ?
Am 19.03.2012 21:09, schrieb Timothy Madden:
In many places in my class template I have to use a nested template from
a base class, with different template parameters. Since the base class
is dependent, I end up with a rather long construct to use throughout my
class:
base_class_name:: template templ_name <arg,...>
From your first description I guess you mean something like
template<class>
struct A {
template<class...>
struct I {};
};
as dependent base class template and usage within B like this:
template<class T>
struct B : A<T> {
typedef A<T> super_t;
typename super_t::template I<T, int> m;
};
Is this correct?
Is there a way like a typedef or a using-declaration to redeclare/import
the template name into my class ?
If you can use C++11 feature, alias templates are ideal for this.
Adapted to the example:
template<class T>
struct B : A<T> {
typedef A<T> super_t;
template<class... Args>
using type = typename super_t::template I<Args...>;
type<T, int> m;
};
The syntax for a using-declaration does not allow to name a template as
the entity. The entity name must end with either a template-id, either a
simple identifier directly, but not with
... :: template _templ_name_
This makes sense since there would then be no way to know if the named
template is a function template or a class template.
Similarly, a typdef declaration may only name a type, but not a template.
Exactly because of this, an alias template looks like the most
appropriate solution for this.
HTH & Greetings from Bremen,
Daniel Kr?gler
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]