I am reading the type of an object from a file:
enum class type_index { ... };
type_index typeidx = read(file_handle, type_index{});
Depending
When you say I have the same generic code for different types; is it possible to wrap it all into a function with same prototype?
If so, you can map each type_index
with a std::function
in order to make the compiler to generate code for each type and to have an easy way to call every function in replacement to a switch.
Switch replacement:
function_map.at(read())();
Running example:
#include
#include