Re: Partial Template Specialization for multiple template arguments
On 3/3/07 11:27 PM, in article
1172953106.534122.154650@64g2000cwx.googlegroups.com, "Philip"
<Montrowe@Hotmail.com> wrote:
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();
};
A template parameter such as t_Option (with a specific type) is called a
"nontype" template parameter.
// partial specialization for second template argument only
template<typename t_Type> // this fails with not enough template
arguments
test<t_Type, true>::Test()
{
...
}
Declaring a partial specialization of a class template is very much like
declaring a general class template - in fact a partial specialization is a
(complete) class template all on its own - as far as C++ is concerned:
template <class t_Type>
class Test<t_Type, true>
{
// fill in completely
};
Essentially, a specialization adds a type parameter list after the class
name, containing at least one specialized type (for a type parameter ) or
value (for a non-type parameter) or even a template (for a template template
parameter).
Three questions:
1) Is this currently part of teh standard?
Partial specialization of class (but not function) templates is part of
Standard C++.
2) If it is, what is the proper way to specify it?
See above.
3) Which compilers, if any, support it?
I would say that any C++ compiler that does not support class template
partial specializations by now would have to be considered outdated,
obsolete or defunct.
Greg
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]