mpl::if_と違い
mpl::eval_if
のThenとElseはtype型を持ったクラス
namespace shand { namespace mpl { // eval_if_c template <bool Cond, class Then, class Else> struct eval_if_c; template <class Then, class Else> struct eval_if_c<true, Then, Else> { typedef typename Then::type type; }; template <class Then, class Else> struct eval_if_c<false, Then, Else> { typedef typename Else::type type; }; // eval_if template <class Cond, class Then, class Else> struct eval_if { typedef typename eval_if_c<Cond::value, Then, Else>::type type; }; }} // namespace shand::mpl
#include <iostream> #include <shand/type_traits.hpp> #include <shand/mpl/eval_if.hpp> using namespace std; using namespace shand; using namespace shand::mpl; struct integer { typedef int type; }; struct character { typedef char type; }; int main() { eval_if<is_integral<int>, integer, character>::type value; cout << typeid(value).name() << endl; return 0; }