Re: Partial Template Specialization for multiple template arguments
Philip wrote:
I may not be calling this the right name, but see the code below.
I often find myself wanting to do this but I cannot figure out how to
write it and get it to compile in MS VC++ 7.1 (Visual Studio 2003).
The examples in Josuttis and so on always show specialization with
just one template argument.
// simply as an example - t_Type can be any typye
// but the t_Option argument has a limited number of values or types
template<typename t_Type, bool t_Option>
class Test
{
public:
Test();
};
// partial specialization for second template argument only
template<typename t_Type> // this fails with not enough template
arguments
test<t_Type, true>::Test()
{
...
}
Well, if the template is named Test, and you refer to it as
test, it's not surprising that it doesn't compile:-). In this
case, too, you can't partially specialize just a function, only
a class. Something like:
template< typename T >
class Test< T, true > { /* ... */ } ;
should work.
Three questions:
1) Is this currently part of the standard?
Partial specialization of class templates is. Partial
specialization of function templates is not (but you can
overload function templates, often getting the same effect).
2) If it is, what is the proper way to specify it?
As above.
3) Which compilers, if any, support it?
I think most, if not all compilers support it in their most
recent releases. If you have to deal with older compilers,
however, you might want to be wary.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]