Template-based wrapper function for boost::bimap lookup not correctly working
I have a pair of functions which, simply put, retrieve the left/right
values of a bimap and print a message (or, depending on a bool arg of the
function, cause a fatal error in the program):
#ifdef __cplusplus
template<typename Lt, typename Rt>
Rt Q_bimapleft( boost::bimap<Lt, Rt> themap, Lt L, bool throwError = false )
{
try
{
Rt returnVal = themap.left.at(L);
return returnVal;
}
catch( ... )
{
if( throwError )
{
Com_Error(ERR_FATAL, "Q_bimapright failure on lookup of %s\n",
boost::lexical_cast<char *, Lt>(L));
}
else
{
Com_Printf(S_COLOR_YELLOW "WARNING: Q_bimapright failure on
lookup of %s\n", boost::lexical_cast<char *, Lt>(L));
}
}
return (Rt)-1;
}
template<typename Lt, typename Rt>
Lt Q_bimapright( boost::bimap<Lt, Rt> themap, Rt R, bool throwError = false )
{
try
{
Lt returnVal = themap.right.at(R);
return returnVal;
}
catch( ... )
{
if( throwError )
{
Com_Error(ERR_FATAL, "Q_bimapleft failure on lookup of %s\n",
boost::lexical_cast<char *, Rt>(R));
}
else
{
Com_Printf(S_COLOR_YELLOW "WARNING: Q_bimapleft failure on
lookup of %s\n", boost::lexical_cast<char *, Rt>(R));
}
}
return (Lt)-1;
}
No comments:
Post a Comment