template<size_t N>
struct DatabaseType
{
typedef int COL_TYPE;
};
unsigned constexpr const_hash(char const *input) {
return *input ?
static_cast<unsigned int>(*input) + 33 * const_hash(input + 1) :
5381;
}
template<>
struct DatabaseType<const_hash("int")>
{
typedef int COL_TYPE;
};
template<>
struct DatabaseType<const_hash("float")>
{
typedef float COL_TYPE;
};
template<>
struct DatabaseType<const_hash("string")>
{
typedef std::string COL_TYPE;
};
void main()
{
auto i = DatabaseType<const_hash("int")>::COL_TYPE(10);
auto f = DatabaseType<const_hash("float")>::COL_TYPE(1.0);
auto f = DatabaseType<const_hash("string")>::COL_TYPE("dasdas");
}
enum Types
{
TYPE_INT,
TYPE_FLOAT,
TYPE_STRING
};
template<Types N>
struct DatabaseType
{
typedef int COL_TYPE;
};
template<>
struct DatabaseType<TYPE_INT>
{
typedef int COL_TYPE;
};
template<>
struct DatabaseType<TYPE_FLOAT>
{
typedef float COL_TYPE;
};
template<>
struct DatabaseType<TYPE_STRING>
{
typedef std::string COL_TYPE;
};
void main()
{
auto i = DatabaseType<TYPE_INT>::COL_TYPE(10);
auto f = DatabaseType<TYPE_FLOAT>::COL_TYPE(1.0f);
auto f = DatabaseType<TYPE_STRING>::COL_TYPE("dasdas");
}