views:

43

answers:

1

I have a struct which indicates a trait:

template<typename T>
struct FooTraits
{
    static const NEbool s_implementsFoo = false;
};

And I can specialize it with a class, thus:

class Apple {};

template<>
struct FooTraits< Apple >
{
   static const NEbool s_implementsFoo = true;
}; 

However currently I cannot use FooTraits if the class I wish to specialize it on is also templatized, thus:

template< typename T >
class Fruit {};

template<>
struct FooTraits< Fruit >
{
   static const NEbool s_implementsFoo = true;
}; 

How should I express this last block of code so any Fruit< T > has s_implementsFoo = true?

Currently the following errors are reported:

error C3203: 'Fruit' : unspecialized class template can't be used as a template argument for template parameter 'T', expected a real type
error C2955: 'Fruit' : use of class template requires template argument list
    see declaration of 'Fruit'
error C2990: 'FooTraits' : non-class template has already been declared as a class template
    see declaration of 'FooTraits'
+3  A: 

Originally I wrote, the FooTraits doesn't depend on the templated argument so why put in a template before I realized my brain fart. That's the downvote and the comments

Can you do this? It's compiling on my machine

template<typename T>
struct FooTraits< Fruit<T> >
{
    static const NEbool s_implementsFoo = true;
};
wheaties
Cuz that's how traits classes work? `Traits<int>::IsInt == true` but `Traits<float>::IsInt == false`
tenpn
@tenpn Yes, I realized that right after I went back to my own project and typed unary_function...
wheaties
Could have sworn I tried that! Thanks :)
Dave Tapley