I have a map which represents a configuration. It\'s a map of std::string and boost::any.
This map is initialized at the start and I\'d
template
bool any_is(const boost::any& a)
{
try
{
boost::any_cast(a);
return true;
}
catch(boost::bad_any_cast&)
{
return false;
}
}
// ...
po::options_description desc;
std::for_each(m_Config.getTuples().begin(),
m_Config.getTuples().end(),
[&desc](const TuplePair& _pair)
{
if(any_is(_pair.first))
{
desc.add_options() { _pair.first, po::value, ""};
}
else if(any_is(_pair.first))
{
desc.add_options() { _pair.first, po::value, ""};
}
else
{
// ...
}
});
// ...
If you have more than a handful of types consider using typelists.