// 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, add_assignable<> > test_concept; any x(1); any y(2); any& z(x += y); BOOST_CHECK_EQUAL(any_cast(x), 3); BOOST_CHECK_EQUAL(&x, &z); } BOOST_AUTO_TEST_CASE(test_int1) { typedef ::boost::mpl::vector, add_assignable<_self, int> > test_concept; any x(1); any& z(x += 2); BOOST_CHECK_EQUAL(any_cast(x), 3); BOOST_CHECK_EQUAL(&x, &z); } BOOST_AUTO_TEST_CASE(test_int2) { typedef ::boost::mpl::vector, add_assignable > test_concept; int x = 1; any y(2); int& z(x += y); BOOST_CHECK_EQUAL(x, 3); BOOST_CHECK_EQUAL(&x, &z); } BOOST_AUTO_TEST_CASE(test_mixed) { typedef ::boost::mpl::vector, common<_b>, add_assignable<_a, _b> > test_concept; tuple t(1.0, 2); any x(get<0>(t)); any y(get<1>(t)); any& z(x += y); BOOST_CHECK_EQUAL(any_cast(x), 3.0); BOOST_CHECK_EQUAL(&x, &z); } BOOST_AUTO_TEST_CASE(test_overload) { typedef ::boost::mpl::vector< common<_a>, common<_b>, add_assignable<_a>, add_assignable<_a, int>, add_assignable, add_assignable<_b>, add_assignable<_b, int>, add_assignable, add_assignable<_a, _b> > test_concept; tuple t(1.0, 2); { any x(get<0>(t)); any y(get<0>(t)); any& z(x += y); BOOST_CHECK_EQUAL(any_cast(x), 2.0); BOOST_CHECK_EQUAL(&x, &z); } { any x(get<0>(t)); int y = 5; any& z(x += y); BOOST_CHECK_EQUAL(any_cast(x), 6.0); BOOST_CHECK_EQUAL(&x, &z); } { double x = 11; any y(get<0>(t)); double& z(x += y); BOOST_CHECK_EQUAL(x, 12); BOOST_CHECK_EQUAL(&x, &z); } { any x(get<1>(t)); any y(get<1>(t)); any& z(x += y); BOOST_CHECK_EQUAL(any_cast(x), 4); BOOST_CHECK_EQUAL(&x, &z); } { any x(get<1>(t)); int y = 5; any& z(x += y); BOOST_CHECK_EQUAL(any_cast(x), 7); BOOST_CHECK_EQUAL(&x, &z); } { double x = 11; any y(get<1>(t)); double& z(x += y); BOOST_CHECK_EQUAL(x, 13); BOOST_CHECK_EQUAL(&x, &z); } { any x(get<0>(t)); any y(get<1>(t)); any& z(x += y); BOOST_CHECK_EQUAL(any_cast(x), 3.0); BOOST_CHECK_EQUAL(&x, &z); } }