enums - C++ Switch on Data Type -
i have attribute
class has enum specifying type of attribute (int_64, uint 64, int_32, string, double, etc.
). attribute class uses boost::any hold vector of types specified enum.
at moment in order work data have big switch statement, , @ least fundamental data types feel there easier way it.
my switch statement looks this:
switch(attribute.type) { case double: stmt->setnumber(col_counter, number(attribute.get_value<double>(row_counter))); break; case int_32: stmt->setnumber(col_counter, number(attribute.get_value<int_32t>(row_counter))); break; }
attribute defined as:
class attribute { public: template <typename t> t get_value(const unsigned index) const { const std::vector<t> * v = boost::any_cast<const std::vector<t> >(&data); return v->at(index); } data_type_enum type; std::string name; boost::any data; }
is there way of avoiding switch statement, doing similar to:
stmt->setnumber(col_counter, number(attribute.get_value<attribute.type>(row_counter)));
well, unfortunately answer no. said r sahu in comment:
not way want to. if get_value function template, can use get_value if attribute.type known integral constant @ compile time.
Comments
Post a Comment