/*============================================================================= 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 #include #include #include #include void test() { using boost::fusion::next; using namespace boost::fusion; using namespace boost; { // Testing deref, next, prior, begin, end char const* s = "Hello"; typedef FUSION_SEQUENCE seq_type; seq_type v(1, 'x', 3.3, s); boost::fusion::result_of::begin::type i(v); BOOST_TEST(*i == 1); BOOST_TEST(*next(i) == 'x'); BOOST_TEST(*next(next(i)) == 3.3); BOOST_TEST(*next(next(next(i))) == s); next(next(next(next(i)))); // end #if !defined(FUSION_NO_PRIOR) BOOST_TEST(*prior(next(next(next(i)))) == 3.3); BOOST_TEST(*prior(prior(next(next(next(i))))) == 'x'); BOOST_TEST(*prior(prior(prior(next(next(next(i)))))) == 1); #endif BOOST_TEST(*begin(v) == 1); #if !defined(FUSION_NO_PRIOR) BOOST_TEST(*prior(end(v)) == s); #endif *i = 3; BOOST_TEST(*i == 3); BOOST_TEST(&*i == &at_c<0>(v)); // prove that it is mutable *i = 987; BOOST_TEST(*i == 987); } { // Testing const sequence and const iterator char const* s = "Hello"; typedef FUSION_SEQUENCE const seq_type; seq_type t(1, 'x', 3.3, s); boost::fusion::result_of::begin::type i(t); BOOST_TEST(*i == 1); BOOST_TEST(*next(i) == 'x'); BOOST_TEST(*begin(t) == 1); #if !defined(FUSION_NO_PRIOR) BOOST_TEST(*prior(end(t)) == s); #endif #ifdef FUSION_TEST_FAIL *i = 3; // must not compile #endif } { // Testing iterator equality typedef FUSION_SEQUENCE seq_type; typedef FUSION_SEQUENCE const cseq_type; typedef boost::fusion::result_of::begin::type vi1; typedef boost::fusion::result_of::begin::type vi2; BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to::value)); BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to::value)); BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to::value)); BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to::value)); BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to::value)); BOOST_STATIC_ASSERT((boost::fusion::result_of::equal_to::value)); } { typedef FUSION_SEQUENCE seq_type; typedef boost::fusion::result_of::begin::type begin_type; typedef boost::fusion::result_of::end::type end_type; typedef boost::fusion::result_of::next::type i1; typedef boost::fusion::result_of::next::type i2; BOOST_STATIC_ASSERT((is_same::value)); } { // testing deref, next, prior, begin, end char const* s = "Hello"; typedef FUSION_SEQUENCE seq_type; seq_type t(1, 'x', 3.3, s); boost::fusion::result_of::begin::type i(t); BOOST_TEST(*i == 1); BOOST_TEST(*next(i) == 'x'); BOOST_TEST(*next(next(i)) == 3.3); BOOST_TEST(*next(next(next(i))) == s); next(next(next(next(i)))); // end #ifdef FUSION_TEST_FAIL next(next(next(next(next(i))))); // past the end: must not compile #endif #if !defined(FUSION_NO_PRIOR) BOOST_TEST(*prior(next(next(next(i)))) == 3.3); BOOST_TEST(*prior(prior(next(next(next(i))))) == 'x'); BOOST_TEST(*prior(prior(prior(next(next(next(i)))))) == 1); #endif BOOST_TEST(*begin(t) == 1); #if !defined(FUSION_NO_PRIOR) BOOST_TEST(*prior(end(t)) == s); #endif *i = 3; BOOST_TEST(*i == 3); BOOST_TEST(*i == at_c<0>(t)); } { // Testing distance typedef FUSION_SEQUENCE seq_type; seq_type t(1, 'x', 3.3, "Hello"); BOOST_STATIC_ASSERT((boost::fusion::result_of::distance< boost::fusion::result_of::begin::type , boost::fusion::result_of::end::type >::value == 4)); BOOST_TEST(distance(begin(t), end(t)).value == 4); } { // Testing tuple iterator boost::fusion::result_of::value_of, boost::fusion::result_of::deref, boost::fusion::result_of::value_at typedef FUSION_SEQUENCE seq_type; typedef boost::fusion::result_of::begin::type i0; typedef boost::fusion::result_of::next::type i1; typedef boost::fusion::result_of::next::type>::type i2; BOOST_STATIC_ASSERT(( is_same::type, int>::value)); BOOST_STATIC_ASSERT(( is_same::type, char&>::value)); BOOST_STATIC_ASSERT(( is_same::type, FUSION_TRAVERSAL_TAG>::value)); BOOST_STATIC_ASSERT((is_same::type, int&>::value)); BOOST_STATIC_ASSERT((is_same::type, char&>::value)); BOOST_STATIC_ASSERT((is_same::type, char&>::value)); BOOST_STATIC_ASSERT((is_same::type, int>::value)); BOOST_STATIC_ASSERT((is_same::type, char&>::value)); BOOST_STATIC_ASSERT((is_same::type, char&>::value)); } { // Testing advance typedef FUSION_SEQUENCE seq_type; seq_type t(1, 'x', 3.3, "Hello"); BOOST_TEST(*advance_c<0>(begin(t)) == at_c<0>(t)); BOOST_TEST(*advance_c<1>(begin(t)) == at_c<1>(t)); BOOST_TEST(*advance_c<2>(begin(t)) == at_c<2>(t)); BOOST_TEST(*advance_c<3>(begin(t)) == at_c<3>(t)); #if !defined(FUSION_NO_PRIOR) BOOST_TEST(*advance_c<-1>(end(t)) == at_c<3>(t)); BOOST_TEST(*advance_c<-2>(end(t)) == at_c<2>(t)); BOOST_TEST(*advance_c<-3>(end(t)) == at_c<1>(t)); BOOST_TEST(*advance_c<-4>(end(t)) == at_c<0>(t)); #endif BOOST_TEST(&*advance_c<0>(begin(t)) == &at_c<0>(t)); BOOST_TEST(&*advance_c<1>(begin(t)) == &at_c<1>(t)); BOOST_TEST(&*advance_c<2>(begin(t)) == &at_c<2>(t)); BOOST_TEST(&*advance_c<3>(begin(t)) == &at_c<3>(t)); } }