Re: Variadic templates
Howard Gardner wrote:
These are the particular stumbling blocks that hurt the worst, and I run
into them fairly often (or, more correctly, I deploy workarounds for
them fairly often).
1) If you write:
template< typename T, T V > struct sometype;
then there's no way to partially specialize it for a particular type. It
seems to me that this should work (but of course it doesn't).
template< int V > struct sometype< int, V >;
..because the partial specialization of "sometype" does not declare a
complete type. A full or partial specialization of a class template
needs to be a complete type in order to instantiate objects with it:
template< int V >
struct sometype< int, V > {};
Now the partial specialization of sometype works. For example:
sometype< int, 7> mytype;
will use the partial specialization above.
2) There is no way to specify a generic nontype template parameter. This
would be nice:
template< nontype > struct something;
template< > struct something< char * >;
template< typename T > something< T * >;
template< typename T > something< T ** >;
so I can write a template that will take an integer, a particular type
of pointer, a reference, a pointer to a pointer to anything, etc.
Why would a nontype parameter be useful here? A "something" template
with one parameterized type, such as:
template< class T > struct something {};
can be specialized in all the ways shown above:
template< > struct something< char * > {};
template< class T > struct something< T * > {};
template< class T > struct something< T ** > {};
Greg
---
[ 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.comeaucomputing.com/csc/faq.html ]