// 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 #include #define BOOST_TEST_MAIN #include using namespace boost::type_erasure; namespace mpl = boost::mpl; template struct tester { int value; }; int func() { return 0; } template int func(tester t0, T... t) { return t0.value + func(t...); } BOOST_TYPE_ERASURE_FREE((has_func), func) template struct common : mpl::vector< copy_constructible > {}; BOOST_AUTO_TEST_CASE(test_arity) { tester<0> t = { 1 }; any, has_func > > x(t); int i = func(x, x, x, x, x, x); BOOST_TEST(i == 6); } BOOST_AUTO_TEST_CASE(test_null_arity) { any, has_func, relaxed> > x; BOOST_CHECK_THROW(func(x, x, x, x, x , x), boost::type_erasure::bad_function_call); } template struct my_concept { static int apply(T0 t0) { return func(t0); } }; BOOST_AUTO_TEST_CASE(test_template_arity) { typedef my_concept<_self, int, int, int, int, int, int> concept1; tester<0> t = { 1 }; any, concept1> > x(t); int i = call(concept1(), x); BOOST_TEST(i == 1); } template struct make_funcN { typedef has_func)> type; }; BOOST_AUTO_TEST_CASE(test_vtable_size) { tester<0> t = { 1 }; any, mpl::transform, make_funcN, mpl::back_inserter< boost::mp11::mp_list<> > >::type > > x(t); tester<7> t1 = { 2 }; int i = func(x, t1); BOOST_TEST(i == 3); }