Jump to content
  • Advertisement
Sign in to follow this  
deks

Tricky template specialization - need help!

This topic is 4329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the following templates:
template<class tType> struct ktTypeInfo
{
    static tBool IsBasicDataType()
    {
        return false;
    }
};

template<> struct ktTypeInfo<tU8> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tS8> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tU16> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tS16> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tU32> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tS32> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tU64> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tS64> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tBool> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tFloat> { static tBool IsBasicDataType() { return true; } };
template<> struct ktTypeInfo<tDouble> { static tBool IsBasicDataType() { return true; } };


And the following one:
template<class tKey, class tType> class ktMap
{
    struct kfPair
    {
        tKey Key;
        tType Elem;
        tU32 HashNext;
    };

    template<> struct ktTypeInfo<kfPair>
    {
        static tBool IsBasicDataType()
        {
            return ktTypeInfo<tKey>::IsBasicDataType() && ktTypeInfo<tType>::IsBasicDataType();
        }
    };

    // ...
}


As you can see, I want to specialize the ktTypeInfo template for ktMap::kfPair, but I can't find a way to to this. I tried to move the definition outside the class without success. Questions: 1. Is it possible? 2. Any better way to do this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I've modified a small part of your code and this is compiling fine with VC++2005 Express.


template<class tKey, class tType>
struct kfPair
{
tKey Key;
tType Elem;
tU32 HashNext;
};

template<class tKey, class tType>
struct ktTypeInfo<kfPair<tKey, tType> >
{
static tBool IsBasicDataType()
{
return (tkTypeInfo<tKey>::IsBasicDataType() && tkTypeInfo<tType>::IsBasicDataType());
}
};

//-----------------------------------------------------------------------------

template<class tKey, class tType>
class ktMap
{
typename kfPair<tKey, tType> Pair;

// ...
};

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!