I'm trying to write a conversion function.
I want to be able do something like this:
//ConversionType_1
Convert<ConversionType_1>("Abc123");
//ConversionType_2
Convert<ConversionType_2>("Abc123");
I want to be able to switch between different data sets.
The solution I've come up with so far seems less than optimal to me:
enum ConversionType
{
ConversionType_1,
ConversionType_2
};
template <ConversionType>
struct Conversion
{
static const int Data[];
static const std::size_t dataSize;
};
template <>
const int Conversion<ConversionType_1>::Data[] = {0,...};
template <>
const std::size_t Conversion<ConversionType_1>::dataSize = 1;
template <ConversionType TConversionType>
void Convert(const std::string& s)
{
if (Conversion<TConversionType>::Data[0])
{}
//...
}
Is there a better way?
I don't like having the enum really.
I thought about having base/derived classes to hold the data but then I have to redeclare the static variables in every derived class.