I've got a type_info
object that defines type of property in my property map. I would like to run some piece of code (e.g. reading value from cin) parametrized with the type that is defined by my type_info object. It could be some template function, i.e.:
template<typename T>
void do_something()
{
T a; cin >> a;
}
Then in some other part of code I would like to call it:
const type_info &type_description = foo.get_type_of_something();
do_some_magic(do_something, type_description);
I'm looking for the do_some_magic
function that calls do_something
specialized for type described by type_descriptor
. The template function can be wrapped in some structure, it doesn't matter.
Of course it is possible only for finite set of types, defined in advance (since specialization must be generated for each at compile time).
One method is to make a chain of if(type_descriptor==typeid(int)) /*...*/ else if(type_descriptor==...
and so on, but this is not very pretty solution (imo).
I'm wondering if there exist more clean solution? Or maybe some library ("boost" preferably) implements such mechanism already?