On Fri, 24 Feb 2006 12:31:02 -0500, Victor Bazarov wrote:
Amadeus W. M. wrote: I have a class
template <class Vector_t>
class A;
where Vector_t is some sort of vector. I want to provide different
specializations for real and for complex vectors. I need the following:
// Real vectors:
A< valarray<double > >; // templated
What do you mean by the word 'templated' in the comment?
A< MyRealVector >; // non-tempalted
// Complex vectors:
A< vector< complex<double> >; // templated
A< MyComplexVector >; // non-templated.
Sorry, I didn't explain very well.
I mean that the template argument of A is itself a template.
So I have the most general
template <class Vector_t>
class A
{
};
I don't want to specialize it to a particular vector type, such as
valarray<double > or MyNonTemplatedV ector. The specializations differ in
the SCALAR type of the vector, but should be irrespective of the actual
container. So what I'd like would be rather
template <class Scalar_t, template<class> class Vector_t>
class A
{
// work on Vector_t<Scalar _t>;
};
Then this should somehow be specialized (1) to Scalar_t = float/double and
(2) to Scalar_t = complex<double> , for instance, but still have the
container Vector_t as a parameter.
I'm reading Stroustrup's book. Can this be done?
Even if it CAN be done, with a template Vector_t I won't be able to have a
A<MyNonTemplate dVector>;
Maybe I should just do
template <class Vector_t>
class RealA
{
};
template <class Vector_t>
class ComplexA
{
};
Then Vector_t is the most general, and I have two implementations - one
for real, one for complex. It won't be transparent to the user though.