// 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; class no_destroy { protected: ~no_destroy() {} }; class with_destroy : public no_destroy { public: ~with_destroy() {} }; template struct common : ::boost::mpl::vector< destructible, copy_constructible, typeid_ > {}; BOOST_AUTO_TEST_CASE(test_basic) { typedef ::boost::mpl::vector > test_concept; with_destroy val; any x(static_cast(val)); no_destroy& ref = any_cast(x); BOOST_CHECK_EQUAL(&ref, &val); } BOOST_AUTO_TEST_CASE(test_increment) { typedef ::boost::mpl::vector > test_concept; int i = 0; any x(i); ++x; BOOST_CHECK_EQUAL(i, 1); } BOOST_AUTO_TEST_CASE(test_add) { typedef ::boost::mpl::vector, addable<> > test_concept; int i = 1; int j = 2; any x(i); any y(j); any z(x + y); int k = any_cast(z); BOOST_CHECK_EQUAL(k, 3); } BOOST_AUTO_TEST_CASE(test_mixed_add) { typedef ::boost::mpl::vector, addable<> > test_concept; int i = 1; int j = 2; any x(i); any y(j); any z(x + y); int k = any_cast(z); BOOST_CHECK_EQUAL(k, 3); }