I have some helper template with templated function. I'm using it for other policy-based templated class to cast or not to cast some value to specific type:
// use this when needed additional value cast
template <typename T>
struct AdditionalValueStaticCaster
{
template <typename U>
static T cast(U u)
{
return static_cast<T>(u);
}
};
// use this specialization when no needed to cast value
template <>
struct AdditionalValueStaticCaster<void>
{
template <typename U>
static U cast(U u)
{
return u;
}
};
Now I want to split these classes to declaration and implementation (.h and .hh files)
So I write declaration like this:
template <typename T>
struct AdditionalValueStaticCaster
{
template <typename U>
static T cast(U u);
};
template <>
struct AdditionalValueStaticCaster<void>
{
template <typename U>
static U cast(U u);
};
And now I want to write implementation. This is ok:
template <typename T>
template <typename U>
T AdditionalValueStaticCaster<T>::cast(U u)
{
return static_cast<T>(u);
}
But this causes error error: too many template-parameter-lists
template<>
template <typename U>
U AdditionalValueStaticCaster<void>::cast(U u)
{
return u;
}
If I delete line template<> all compiles ok, but I still have a question: is it right solution or I missed something?