の型にへの暗黙的な変換がないboost::any_cast<T>
場合にのみ、例外をスローしたいと考えています。通常の動作は、暗黙的な変換に関係なく、型がis notの場合に例外をスローするようです。any
T
any
T
例:
boost::any a = 1;
boost::any_cast<int>(a); // This succeeds, and rightfully so
boost::any_cast<long>(a); // I don't want this to throw
boost::any_cast<Widget>(a); // I want this to throw
必要な機能を取得する簡単な方法があるかどうか、または既存の動作がそのようになっている理由を教えてください。