I have a boost::variant
of types such as:
typedef boost::variant< uint8_t, int8_t, uint16_t, int16_t,
uint32_t, int32_t, float, double, std::string > StorageTt;
A StorageTt
variable, say val
, is set to one of these storage types later in my code. I'd like to retrieve the type that val
currently holds to define more variables of that same type. So if val
is currently a uint16_t
, I want to do something like:
typedef decltype(typeid(val)) StorageTt;
StorageTt new_val = 42; // new_val should be a uint16_t
but this yields a const type_info
type. I know I can do:
switch (val.which()) {
case 0: // uint8_t
case 1: //...
but I'd rather avoid the long switch-statement, because I have to do this multiple times.