// Boost.TypeErasure library // // Copyright 2011 Steven Watanabe // // Distributed under the Boost Software License Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // $Id$ #include #include #include #include #include #include #define BOOST_TEST_MAIN #include using namespace boost::type_erasure; template struct common : ::boost::mpl::vector< destructible, copy_constructible, typeid_ > {}; BOOST_AUTO_TEST_CASE(test_same) { typedef ::boost::mpl::vector, addable<> > test_concept; any x(1); any y(2); any z(x + y); int i = any_cast(z); BOOST_CHECK_EQUAL(i, 3); } BOOST_AUTO_TEST_CASE(test_int1) { typedef ::boost::mpl::vector, addable<_self, int> > test_concept; any x(1); any z(x + 2); int i = any_cast(z); BOOST_CHECK_EQUAL(i, 3); } BOOST_AUTO_TEST_CASE(test_int2) { typedef ::boost::mpl::vector, addable > test_concept; any x(1); any z(2 + x); int i = any_cast(z); BOOST_CHECK_EQUAL(i, 3); } BOOST_AUTO_TEST_CASE(test_mixed) { typedef ::boost::mpl::vector, common<_b>, addable<_a, _b> > test_concept; tuple x(1.0, 2); any z(get<0>(x) + get<1>(x)); double d = any_cast(z); BOOST_CHECK_EQUAL(d, 3); } BOOST_AUTO_TEST_CASE(test_overload) { typedef ::boost::mpl::vector< common<_a>, common<_b>, addable<_a>, addable<_a, int>, addable, addable<_b>, addable<_b, int>, addable, addable<_a, _b> > test_concept; tuple t(1.0, 2); any x(get<0>(t)); any y(get<1>(t)); { any z(x + x); BOOST_CHECK_EQUAL(any_cast(z), 2.0); } { any z(x + 3); BOOST_CHECK_EQUAL(any_cast(z), 4.0); } { any z(3 + x); BOOST_CHECK_EQUAL(any_cast(z), 4.0); } { any z(y + y); BOOST_CHECK_EQUAL(any_cast(z), 4); } { any z(y + 3); BOOST_CHECK_EQUAL(any_cast(z), 5); } { any z(3 + y); BOOST_CHECK_EQUAL(any_cast(z), 5); } { any z(x + y); BOOST_CHECK_EQUAL(any_cast(z), 3); } }