Jump to content
  • Advertisement
Sign in to follow this  
Trillian

Template specialisation - won't compile

This topic is 4338 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

Hello! I'm having a little trouble with some template-specialized functions. The functions perform byte-swapping (small to big endian for example) and are defined as follow :
// Default function, if it is called, the SWAPBYTES template argument
// has not been specialised
template<CRYO_uint SWAPBYTES>
CRYO_INLINE CRYO_void * ByteSwap(CRYO_void * in_data, CRYO_uint in_elements)
{
    CRYO_NOT_IMPLEMENTED("Swap size for ByteSwap function");

    return in_data;
}

// Specialized overloads
template<> // LABEL : A
CRYO_INLINE CRYO_void * ByteSwap<1>(CRYO_void * in_data, CRYO_uint in_elements)
{ // LABEL : B
    return in_data;
}

template<>
CRYO_INLINE CRYO_void * ByteSwap<2>(CRYO_void * in_data, CRYO_uint in_elements)
{
    for(CRYO_uint i = 0 ; i < in_elements ; ++i)
    {
        CRYO_ushort & elem = *((CRYO_ushort*)in_data + in_elements);
        elem = elem << 8 | elem >> 8;
    }

    return in_data;
}

template<>
CRYO_INLINE CRYO_void * ByteSwap<4>(CRYO_void * in_data, CRYO_uint in_elements)
{
    for(CRYO_uint i = 0 ; i < in_elements ; ++i)
    {
        CRYO_uint & elem = *((CRYO_uint*)in_data + in_elements);
        elem = elem << 24 | elem >> 24 | ((elem << 8) & 0x00FF0000) | ((elem >> 8) & 0x0000FF00);
    }

    return in_data;
}

These functions are located into namespace Cryo::class System. I'm using Code::Blocks along with that gcc-thing compiler and I get the following errors : -invalid explicit specialization before '>' token (at line labelled A) -explicit specialization in non-namespace scope `class Cryo::System' (at line labelled A) -invalid member function declaration (at line labelled B) What am I doing wrong here? Can anyone help? EDIT: Now that I think about it... the problem might come from the compiler as I don't recall having any problem compiling this under VC++. I will change this code to a way that does not use templates but I'm still curious about this. [Edited by - Trillian on January 31, 2007 6:08:29 PM]

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!