At my workplace, I am working on a use case where I have to convert multiple internal/product level data types to C++ compatible data types. Earlier we used something called as switch fence where code would look like
switch(InternalTypeCategory)
{
case InternalTypeA:
convert_to_int8_t;
break;
case InternalTypeB:
convert_to_int16_t
break;
.....
}
But for the sake of performance and other related issues, we are going to convert this switch fence block to C++ template based code where we dont have use switch case every now and then.
What have I tried so far?
I have been playing around with boost::any, boost::variant and boost::any_cast, boost::numeric_cast but nothing concrete has come up so far. I always end up with repetition of code or use some sort of mechanism (control structures or hash table) to select the particular value to have enough information for type conversion.
The internal/product level data types are variants (in terms of size, signed/unsigned) of integer, floating point, double and character.
Kindly help. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire