全ての型を継承する型を定義
Boost.MPL の inherit を使用すれば、テンプレート引数型を全て継承する型を定義することが出来ます。
[ソース]
#include <boost/mpl/inherit.hpp> #include <iostream> #include <type_traits> struct X1{ int value; }; struct X2{ void func() const{ std::cout << "X2" << std::endl; } }; int main(){ typedef boost::mpl::inherit<X1, X2>::type X; static_assert(std::is_base_of<X1, X>{}, ""); static_assert(std::is_base_of<X2, X>{}, ""); X x; x.value = 10; x.func(); return 0; }
[出力]
X2
[boost]
- ver 1.50.0