#include // for testing only #include #include #include #include #include #include namespace _bi=boost::_bi; namespace mpl=boost::mpl; namespace fusion=boost::fusion; namespace result_of=boost::fusion::result_of; using boost::fusion::bind_arg_sequence_iterator; using boost::mpl::equal; #include #include struct T{}; typedef _bi::list0 _list0; typedef _bi::list1 _list1; typedef _bi::list2 _list2; typedef _bi::list3 _list3; typedef _bi::list4 _list4; typedef _bi::list5 _list5; typedef _bi::list6 _list6; typedef _bi::list7 _list7; typedef _bi::list8 _list8; typedef _bi::list9 _list9; template void do_checks() { BOOST_MPL_ASSERT(( _bi::is_bind_sequence )); BOOST_STATIC_ASSERT((size==_bi::bind_sequence_size::value)); // can't do type at index check here... doh } MPL_TEST_CASE() { #define BS_CHECK(N) do_checks() BS_CHECK(0); BS_CHECK(1); BS_CHECK(2); BS_CHECK(3); BS_CHECK(4); BS_CHECK(5); BS_CHECK(6); BS_CHECK(7); BS_CHECK(8); BS_CHECK(9); #undef BS_CHECK MPL_ASSERT_NOT (( _bi::is_bind_sequence )); MPL_ASSERT_NOT (( _bi::is_bind_sequence )); MPL_ASSERT(( equal<_bi::type_at_index<_list1,0>::type,int> )); MPL_ASSERT(( equal<_bi::type_at_index<_list9,8>::type, double> )); MPL_ASSERT(( equal<_bi::type_at_index<_list7,3>::type,char> )); } MPL_TEST_CASE() { typedef bind_arg_sequence_iterator<_list1,0> first; typedef result_of::value_of::type type; BOOST_MPL_ASSERT((boost::is_same < int, result_of::value_of::type >)); BOOST_MPL_ASSERT((boost::is_same < int&, result_of::deref::type >)); } MPL_TEST_CASE() { typedef bind_arg_sequence_iterator<_list9,2> first; typedef result_of::value_of::type type; BOOST_MPL_ASSERT((boost::is_same < int &, type>)); BOOST_MPL_ASSERT((boost::is_same < int &, result_of::deref::type >)); } #include #include MPL_TEST_CASE() { typedef _bi::list4 list_t; typedef result_of::begin::type first; BOOST_STATIC_ASSERT(( first::index::value==0 )); typedef result_of::next::type second; BOOST_STATIC_ASSERT(( second::index::value==1 )); typedef result_of::next::type third; BOOST_MPL_ASSERT((boost::is_same< int, result_of::value_of::type >)); BOOST_MPL_ASSERT((boost::is_same< char, result_of::value_of::type >)); BOOST_MPL_ASSERT((boost::is_same< char &, result_of::value_of::type >)); char c='h'; list_t l(1,'e',c,1.); first f(l); } #include MPL_TEST_CASE() { typedef _bi::list3 list3; typedef result_of::begin::type first; BOOST_MPL_ASSERT(( boost::is_same >::type )); BOOST_MPL_ASSERT(( boost::is_same ::type, int >::type )); typedef result_of::next::type second; BOOST_MPL_ASSERT(( boost::is_same >::type )); BOOST_MPL_ASSERT(( boost::is_same ::type, double >::type)); typedef result_of::next::type third; BOOST_MPL_ASSERT(( boost::is_same >::type)); BOOST_MPL_ASSERT(( boost::is_same ::type, char >::type)); } #include #include #include #include template void test_fwd_impl() { typedef typename result_of::begin::type first; BOOST_MPL_ASSERT(( mpl::not_ > )); typedef typename result_of::end::type end; BOOST_MPL_ASSERT(( mpl::not_ > )); BOOST_STATIC_ASSERT(( result_of::size::value == Size )); } template void test_fwd() { test_fwd_impl(); BOOST_STATIC_ASSERT(( ! result_of::empty::value )); typedef typename result_of::begin::type first; // only nonempty sequences iterators can be derefernced typedef typename result_of::front::type front; typedef typename result_of::deref::type first_type; BOOST_MPL_ASSERT(( boost::is_same )); } template<> void test_fwd<_bi::list0,0>() { test_fwd_impl<_bi::list0,0>(); // additionally want to check that its empty BOOST_STATIC_ASSERT(( result_of::empty<_bi::list0>::value )); } MPL_TEST_CASE() { // test fwd sequence stuff #define BS_CHECK(N) test_fwd() BS_CHECK(0); BS_CHECK(1); BS_CHECK(2); BS_CHECK(3); BS_CHECK(4); BS_CHECK(5); BS_CHECK(6); BS_CHECK(7); BS_CHECK(8); BS_CHECK(9); #undef BS_CHECK } #include #include #include #include #include #include template void find_type() { typedef typename result_of::find_if >::type find_it; typedef typename result_of::value_of::type found_type; BOOST_MPL_ASSERT(( boost::is_same )); // now count all the types FindType typedef typename result_of::filter_if < BindSequence , boost::is_same >::type filter_type; // and make sure there is atleast 1 BOOST_STATIC_ASSERT(( result_of::size::value >= 1)); } MPL_TEST_CASE() { // test some algorithms find_type<_list1,int>(); find_type<_list2,int>(); find_type<_list3,int>(); find_type<_list4,int>(); find_type<_list5,int>(); find_type<_list6,int>(); find_type<_list7,char>(); find_type<_list8,int>(); find_type<_list9,int &>(); } #include template struct argument_position_impl { typedef mpl::int_<0> type; }; template struct argument_position_impl(*)()> { typedef mpl::int_ type; }; struct argument_position { template struct result { typedef typename argument_position_impl::type type; }; }; template struct placeholders { typedef typename boost::bind_arg_sequence::type bind_arg_sequence; typedef typename result_of::filter_if < bind_arg_sequence , boost::is_placeholder >::type placeholders_list; }; template struct count_placeholders_impl_assert; template struct count_placeholders_impl_assert<0,BindExpression> { typedef typename placeholders::placeholders_list placeholders_list; BOOST_STATIC_ASSERT(( result_of::size::value == 0)); }; template struct count_placeholders_impl_assert { typedef typename placeholders::placeholders_list placeholders_list; BOOST_STATIC_ASSERT(( result_of::size::value == NumPlaceholders)); typedef typename result_of::begin::type first; typedef typename result_of::value_of::type first_type; BOOST_STATIC_ASSERT(( argument_position_impl::type::value > 0 )); }; template void count_placeholders(BindExpression) { count_placeholders_impl_assert(); } void fn_0(){} void fn_1(int){} void fn_2(int,int){} void fn_3(int,int,int){} void fn_4(int,int,int,int){} MPL_TEST_CASE() { count_placeholders<0>(boost::bind(&fn_0)); count_placeholders<1>(boost::bind(&fn_1,_1)); int a = 5; count_placeholders<1>(boost::bind(&fn_2,a,_2)); count_placeholders<3>(boost::bind(&fn_3,_1,_2,_3)); count_placeholders<4>(boost::bind(&fn_4,_1,_2,_3,_4)); } #include #include #include #include #include template void min_arity(BindExpression const &) { typedef typename placeholders::placeholders_list placeholders_list; typedef typename result_of::transform< placeholders_list, argument_position >::type arg_positions; typedef typename mpl::max_element< arg_positions>::type iter; typedef typename result_of::empty::type no_placeholders; typedef typename mpl::eval_if< no_placeholders, mpl::int_<0>, mpl::deref >::type min_arity_type; BOOST_MPL_ASSERT(( boost::is_same >)); } MPL_TEST_CASE() { min_arity<0>(boost::bind(&fn_0)); min_arity<5>(boost::bind(&fn_2,_4,_5)); min_arity<1>(boost::bind(&fn_1,_1)); int a=9; min_arity<2>(boost::bind(&fn_3,a,_1,_2)); min_arity<3>(boost::bind(&fn_3,_1,_2,_3)); min_arity<4>(boost::bind(&fn_3,a,a,_4)); min_arity<9>(boost::bind(&fn_3,_7,_9,_8)); } int main() { return boost::report_errors(); }