BOOST_TYPE_ERASURE_MEMBER
Boost.TypeErasure に BOOST_TYPE_ERASURE_MEMBER というマクロが用意されており、これを使用すれば簡単に Concept を定義出来ます。
使い方はこんな感じ。
[ソース]
#include <boost/type_erasure/any.hpp> #include <boost/type_erasure/member.hpp> #include <boost/mpl/vector.hpp> #include <boost/range/algorithm/for_each.hpp> #include <vector> BOOST_TYPE_ERASURE_MEMBER((my_concept)(has_push_back), push_back, 1) int main(){ namespace te = boost::type_erasure; typedef boost::mpl::vector< my_concept::has_push_back<void(int)>, te::copy_constructible<> > concept_type; std::vector<int> vec; te::any<concept_type, te::_self&> x(vec); x.push_back(1); x.push_back(2); x.push_back(3); x.push_back(4); x.push_back(5); boost::for_each(vec, [](int n){ std::cout << n << std::endl; }); return 0; }
[出力]
1 2 3 4 5
なかなかいいかんじですね。