boost::optionalは成功か失敗かしかわからないので 失敗した理由付きのoptionalがほしいよね、という話がTwitterでありました。 Maybeモナド(boost::optional)に対するEitherモナドのように boost::eitherという名前だと仮定して、こんな感じで使えるといいんじゃないかな、と。 either<int> foo(int a) { typedef either<int> result_type; return a >= 0 ? a : result_type("invalid argument", result_type::error_tag()); } either<int> x = foo(-1); if (!x) cout << x.what() << endl; cout << x.get() << endl; エラーがネストしてた