/*============================================================================= Copyright (C) 1999-2003 Jaakko Jarvi Copyright (c) 2001-2011 Joel de Guzman 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) ==============================================================================*/ #include #include #include #include #include #include #include #include #include #include #include #if !defined(FUSION_AT) #define FUSION_AT at_c #endif #if !defined(FUSION_SIZE) #define FUSION_SIZE boost::fusion::result_of::size #endif template struct is_same { }; struct test_intrinsics1 { // test at, begin, end, next, prior, advance, size, deref, etc. typedef boost::fusion::FUSION_SEQUENCE sequence; typedef boost::mpl::begin::type first; typedef boost::mpl::next::type second; typedef boost::mpl::next::type third; typedef boost::mpl::next::type fourth; typedef boost::mpl::end::type last; BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, int>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, float>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, bool>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, char>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::at_c::type, bool>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::front::type, int>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref< boost::mpl::advance_c::type>::type, char>::value)); BOOST_STATIC_ASSERT((boost::mpl::size::value == 4)); BOOST_STATIC_ASSERT(!(boost::mpl::empty::value)); BOOST_STATIC_ASSERT((boost::mpl::distance::value == 2)); #if !defined(FUSION_FORWARD_ONLY) // list has no back/prev typedef boost::mpl::prior::type fourth_; typedef boost::mpl::prior::type third_; typedef boost::mpl::prior::type second_; typedef boost::mpl::prior::type first_; BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, int>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, float>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, bool>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, char>::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::back::type, char>::value)); #endif }; struct test_intrinsics2 { typedef boost::fusion::FUSION_SEQUENCE<> seq0; #if !defined(BOOST_FUSION_SEQUENCE_CONVERSION_IS_NOT_SEQUENCE__TYPE_PRESERVING) #if !defined(FUSION_FORWARD_ONLY) // list has no back/prev typedef boost::fusion::FUSION_SEQUENCE target1; typedef boost::mpl::push_back::type seq1; BOOST_STATIC_ASSERT((boost::mpl::equal::value)); typedef boost::fusion::FUSION_SEQUENCE target2; typedef boost::mpl::push_back::type seq2; BOOST_STATIC_ASSERT((boost::mpl::equal::value)); #endif typedef boost::fusion::FUSION_SEQUENCE target3; typedef boost::mpl::push_front::type seq3; BOOST_STATIC_ASSERT((boost::mpl::equal::value)); typedef boost::fusion::FUSION_SEQUENCE target4; typedef boost::mpl::push_front::type seq4; BOOST_STATIC_ASSERT((boost::mpl::equal::value)); #endif }; void test() { using namespace boost::fusion; { // testing const sequences const FUSION_SEQUENCE t1(5, 3.3f); BOOST_TEST(FUSION_AT<0>(t1) == 5); BOOST_TEST(FUSION_AT<1>(t1) == 3.3f); } { // testing at works with MPL integral constants const FUSION_SEQUENCE t1(101, 'z'); BOOST_TEST(boost::fusion::at >(t1) == 101); BOOST_TEST(boost::fusion::at >(t1) == 'z'); // explicitly try something other than mpl::int_ BOOST_TEST((boost::fusion::at >(t1) == 101)); BOOST_TEST((boost::fusion::at >(t1) == 'z')); } { // testing size & empty typedef FUSION_SEQUENCE t1; typedef FUSION_SEQUENCE<> t2; BOOST_STATIC_ASSERT(FUSION_SIZE::value == 3); BOOST_STATIC_ASSERT(FUSION_SIZE::value == 0); BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty::value); BOOST_STATIC_ASSERT(boost::fusion::result_of::empty::value); } { // testing front & back typedef FUSION_SEQUENCE tup; tup t(1, 2.2f, "Kimpo"); BOOST_TEST(front(t) == 1); #if !defined(FUSION_FORWARD_ONLY) // list has no back BOOST_TEST(back(t) == "Kimpo"); #endif } { // testing is_sequence typedef FUSION_SEQUENCE t1; typedef FUSION_SEQUENCE<> t2; typedef FUSION_SEQUENCE t3; BOOST_STATIC_ASSERT(traits::is_sequence::value); BOOST_STATIC_ASSERT(traits::is_sequence::value); BOOST_STATIC_ASSERT(traits::is_sequence::value); BOOST_STATIC_ASSERT(!traits::is_sequence::value); BOOST_STATIC_ASSERT(!traits::is_sequence::value); } { // testing mpl::is_sequence typedef FUSION_SEQUENCE t1; typedef FUSION_SEQUENCE<> t2; typedef FUSION_SEQUENCE t3; BOOST_STATIC_ASSERT(boost::mpl::is_sequence::value); BOOST_STATIC_ASSERT(boost::mpl::is_sequence::value); BOOST_STATIC_ASSERT(boost::mpl::is_sequence::value); } { // testing mpl compatibility // test begin, end, next, prior, advance, size, deref, etc. //~ typedef FUSION_SEQUENCE tuple_type; //~ test_intrinsics1 test1; //~ (void)test1; // prevent unused variable warning // test an algorithm typedef FUSION_SEQUENCE t1; typedef boost::mpl::find::type iter; typedef boost::mpl::deref::type type; BOOST_STATIC_ASSERT((boost::is_same::value)); } }