Boost.TypeErasure の any で暗黙の型変換が行われるようになっていた
以前、『Boost.TypeErasure の any は暗黙の型変換が行われない』という記事を書いたのですが、リリース版の Boost.TypeErasure(Boost 1.54.0)ではこの挙動が変更されており、暗黙の型変換が行われるようになっていました。
[ソース]
#include <boost/type_erasure/any.hpp> #include <boost/type_erasure/operators.hpp> #include <boost/mpl/vector.hpp> #include <iostream> #include <string> typedef boost::mpl::vector< boost::type_erasure::ostreamable<>, boost::type_erasure::addable<>, boost::type_erasure::copy_constructible<> > twice_disp_concept; void twice_disp(boost::type_erasure::any<twice_disp_concept> const& any){ std::cout << (any + any) << std::endl; } int main(){ // OK twice_disp(boost::type_erasure::any<twice_disp_concept>(10)); twice_disp(boost::type_erasure::any<twice_disp_concept>(std::string("homu"))); // OK twice_disp(10); twice_disp(std::string("homu")); return 0; }
[出力]
20 homuhomu 20 homuhomu
個人的に暗黙の型変換が行われなかったのは煩わしかったので、これは嬉しい変更です。
[boost]
- ver 1.54.0