/*============================================================================= Copyright (c) 1999-2003 Jaakko Jarvi Copyright (c) 2001-2013 Joel de Guzman Copyright (c) 2006 Dan Marsden 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 #include #include struct k1 {}; struct k2 {}; struct k3 {}; struct k4 {}; template struct is_same { }; namespace fn = boost::fusion; struct test_intrinsics1 { // test at, begin, end, next, prior, advance, size, deref, etc. typedef fn::map< fn::pair, fn::pair, fn::pair, fn::pair > 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, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::at_c::type, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::front::type, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref< boost::mpl::advance_c::type>::type, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::mpl::size::value == 4)); BOOST_STATIC_ASSERT(!(boost::mpl::empty::value)); BOOST_STATIC_ASSERT((boost::mpl::distance::value == 2)); 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, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::deref::type, fn::pair >::value)); BOOST_STATIC_ASSERT((boost::is_same< boost::mpl::back::type, fn::pair >::value)); }; void test() { using namespace boost::fusion; { // testing const sequences const map, pair > t1(5, 3.3f); BOOST_TEST(at_c<0>(t1).second == 5); BOOST_TEST(at_c<1>(t1).second == 3.3f); } { // testing at works with MPL integral constants const map, pair > t1(101, 'z'); BOOST_TEST(boost::fusion::at >(t1).second == 101); BOOST_TEST(boost::fusion::at >(t1).second == 'z'); // explicitly try something other than mpl::int_ BOOST_TEST((boost::fusion::at >(t1).second == 101)); BOOST_TEST((boost::fusion::at >(t1).second == 'z')); } { // testing size & empty typedef map, pair, pair > t1; typedef map<> t2; BOOST_STATIC_ASSERT(boost::fusion::result_of::size::value == 3); BOOST_STATIC_ASSERT(boost::fusion::result_of::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 map, pair, pair > tup; tup t(1, 2.2f, std::string("Kimpo")); BOOST_TEST(front(t).second == 1); BOOST_TEST(back(t).second == "Kimpo"); } { // testing is_sequence typedef map, pair, pair > t1; typedef map<> t2; typedef map > 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 map, pair, pair > t1; typedef map<> t2; typedef map > 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 an algorithm typedef map, pair, pair > t1; typedef boost::mpl::find >::type iter; typedef boost::mpl::deref::type type; BOOST_STATIC_ASSERT((boost::is_same >::value)); } } int main() { test(); return boost::report_errors(); }