Is there any way (function/structs/templates) etc. in c++ where in if we provide strings like int,float etc. as input and then it returns corresponding type. To elaborate a scenario suppose from DB I was able to retrieve that data type of column say ITEM_NAME have type varchar (as std::string) so now i want to declare a c++ variable item_name(std::string) whose type will be corresponding to this column ITEM_NAME(varchar). Below is something i tried (sample code) but this is not working :
template<string coltype>
struct DatabaseType
{
typedef COL_TYPE std::string;
};
template<string coltype="int">
{
typedef COL_TYPE int;
};
std::string getDBType()
{
return "int";
}
int main()
{
DataBaseType<std::string("int")>::COL_TYPE x;
return 0;
};
Aucun commentaire:
Enregistrer un commentaire