Topic: Q: Specializing templates with complex<T> or other templates


Author: "Jim Saffle" <jsaffle@erols.com>
Date: 1998/03/15
Raw View
I have a template that is to be specialized with some numeric type:

template <class T>
class foo
{
    public:
        void    doSomething();
};

foo<T> contains a number of member functions of which only the method
doSomething() differs depending on T being real or complex. I could
specialize
the template for complex types:

template <class T> class foo< complex<T> >

But that would involve copying the unchanged code from the original
template. I could specialize doSomething() for each complex<T>
that I expect.  What I really would like to do is:

// for all real T
template <class T>
void        foo<T>::doSomething() { /* real number behavior */; }

// for all complex T
template <class T>
void        foo< complex<T> >::doSomething() { /* complex number behavior
*/; }

What does the standard say about this?

Thanks,

Jim
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]