簡単に言えば、バイマップの左/右の値を取得してメッセージを出力する関数のペアがあります (または、関数の bool 引数によっては、プログラムで致命的なエラーが発生します)。
#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;
}
#endif
ただし、関数を使用する場合:
....
boost::bimap<int, std::string> animTable;
char token[1024];
....
int index = Q_bimapleft<int, std::string>(animTable, token);
Intellisense/コンパイラ レポート:
IntelliSense: no instance of function template "Q_bimapleft" matches the argument list