BOOST_TYPE_ERASURE_MEMBER で const なメンバ関数の呼び出し方
以前、『BOOST_TYPE_ERASURE_MEMBER では const なメンバ関数が呼び出せない』という記事を書いたのですが定義が間違っていました。
下記のように _self const を記述する事で const なメンバ関数も問題なく処理することが出来ました。
[ソース]
#include <boost/type_erasure/any.hpp> #include <boost/type_erasure/member.hpp> #include <boost/mpl/vector.hpp> BOOST_TYPE_ERASURE_MEMBER((has_call), call, 0) struct X{ void call() const{ std::cout << "X::call() const" << std::endl; } }; int main(){ namespace te = boost::type_erasure; typedef boost::mpl::vector< // _self const を定義する ::has_call<void(), te::_self const>, te::copy_constructible<> > concept_type; X x; te::any<concept_type> a1(x); a1.call(); // OK te::any<concept_type> const a2(x); a2.call(); // OK return 0; }
[出力]
X::call() const X::call() const