Boost.TypeErasure の any でデフォルトコンストラクタを使用する
any のデフォルトコンストラクタを使用する場合は Concept に relaxed_match を定義する必要があります。
[ソース]
#include <boost/type_erasure/any.hpp> #include <boost/type_erasure/member.hpp> #include <boost/mpl/vector.hpp> #include <iostream> BOOST_TYPE_ERASURE_MEMBER((has_call), call, 1) struct X { void call(int n){ std::cout << "X::call(" << n << ")" << std::endl; } }; int main(){ namespace te = boost::type_erasure; te::any< boost::mpl::vector< ::has_call<void(int)>, te::copy_constructible<>, te::relaxed_match // これを定義する > > any_callable; any_callable = X(); any_callable.call(42); return 0; }
[出力]
X::call(42)
ドキュメントに見当たらなかったんだけどどこかに書いてあるのかしら。