A
andreas.schniertshauer
Hello,
I have a class template of the following form:
template <typename T, typename F>
class Converter
{
public:
bool operator () (T& tTo, const F& tFrom) const;
};
And I want to do a specialization where F could be a long or unsigned long type:
template <>
class Converter<string, F>
{
public:
bool Converter<string, F>:perator () ( string& tTo, const F& tFrom ) const
{
static_assert( std::is_integral<F>::value && (std::is_signed<F>::value || std::is_unsigned<F>::value), "Error: type not supported" );
...
if ( std::is_signed<F>::value )
{
// do something with long
}
else
if ( std::is_unsigned<F>::value )
{
// do something with unsigned long
}
...
return true;
}
};
Can anyone tell me please how I could write the specialized template class so that I could pass a long or unsigned long? Or isn't this possible to do in one class and I must write two specialized classes one specialization for long and one for unsigned long? I want to have less code, so the second solution would not be my favorite.
Thanks for the help,
Andreas.
I have a class template of the following form:
template <typename T, typename F>
class Converter
{
public:
bool operator () (T& tTo, const F& tFrom) const;
};
And I want to do a specialization where F could be a long or unsigned long type:
template <>
class Converter<string, F>
{
public:
bool Converter<string, F>:perator () ( string& tTo, const F& tFrom ) const
{
static_assert( std::is_integral<F>::value && (std::is_signed<F>::value || std::is_unsigned<F>::value), "Error: type not supported" );
...
if ( std::is_signed<F>::value )
{
// do something with long
}
else
if ( std::is_unsigned<F>::value )
{
// do something with unsigned long
}
...
return true;
}
};
Can anyone tell me please how I could write the specialized template class so that I could pass a long or unsigned long? Or isn't this possible to do in one class and I must write two specialized classes one specialization for long and one for unsigned long? I want to have less code, so the second solution would not be my favorite.
Thanks for the help,
Andreas.