/*============================================================================= 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 #include #include struct X { operator char const*() const { return ""; } }; int main() { using namespace boost::fusion; namespace fusion = boost::fusion; std::cout << tuple_open('['); std::cout << tuple_close(']'); std::cout << tuple_delimiter(", "); /// Testing joint_view { vector t1(3); vector t2; typedef joint_view, vector > view_type; view_type view(t1, t2); std::cout << view << std::endl; BOOST_TEST((view == make_vector(3, X()))); } { vector t1(3, 'x'); vector t2; typedef joint_view, vector > view_type; view_type view(t1, t2); std::cout << view << std::endl; BOOST_TEST((view == make_vector(3, 'x', X()))); *begin(view) = 4; BOOST_TEST(at_c<0>(t1) == 4); } { vector t1(3, 'x'); vector t2; typedef joint_view, vector > view_type; view_type view(t1, t2); std::cout << view << std::endl; BOOST_TEST((view == make_vector(3, 'x', X(), 0))); } { typedef vector t1_type; t1_type t1(777); typedef vector t2_type; t2_type t2(1, 'x', 3.3); { typedef joint_view view_type; view_type view(t1, t2); std::cout << view << std::endl; BOOST_TEST((view == make_vector(777, 1, 'x', 3.3))); } { typedef joint_view view_type; view_type view(t2, t1); std::cout << view << std::endl; BOOST_TEST((view == make_vector(1, 'x', 3.3, 777))); } { typedef joint_view jv_type; typedef joint_view jv2_type; jv_type jv(t2, t1); jv2_type jv2(jv, jv); std::cout << jv << std::endl; std::cout << jv2 << std::endl; BOOST_TEST(jv2 == make_vector(1, 'x', 3.3, 777, 1, 'x', 3.3, 777)); } { typedef joint_view jt_type; typedef joint_view jv2_type; typedef joint_view jv3_type; jt_type jt(t2, t1); jv2_type jv2(t1, t2); jv3_type jv3(jt, jv2); std::cout << jt << std::endl; std::cout << jv2 << std::endl; std::cout << jv3 << std::endl; BOOST_TEST(jv3 == make_vector(1, 'x', 3.3, 777, 777, 1, 'x', 3.3)); } { typedef joint_view, t1_type> jt_type; vector<> empty; jt_type jt(empty, t1); std::cout << jt << std::endl; BOOST_TEST(jt == make_vector(777)); } { typedef joint_view > jt_type; vector<> empty; jt_type jt(t1, empty); std::cout << jt << std::endl; BOOST_TEST(jt == make_vector(777)); } { typedef joint_view, vector<> > jt_type; vector<> empty; jt_type jt(empty, empty); std::cout << jt << std::endl; BOOST_TEST(jt == make_vector()); } } { typedef map > map_type; map_type m(make_pair(0)); typedef set set_type; set_type s("foo", 1.3f); typedef joint_view joint_view_type; joint_view_type j(m,s); BOOST_MPL_ASSERT((boost::fusion::result_of::has_key::type)); BOOST_MPL_ASSERT((boost::fusion::result_of::has_key::type)); BOOST_MPL_ASSERT((boost::fusion::result_of::has_key::type)); BOOST_MPL_ASSERT((boost::is_same::type>::type, void>)); BOOST_MPL_ASSERT((boost::is_same::type>::type>::type, std::string>)); BOOST_MPL_ASSERT((boost::is_same< boost::fusion::result_of::key_of::type>::type>::type>::type , float>)); BOOST_MPL_ASSERT((boost::is_same::type>::type, int>)); BOOST_MPL_ASSERT((boost::is_same::type>::type>::type, std::string>)); BOOST_MPL_ASSERT((boost::is_same< boost::fusion::result_of::value_of_data::type>::type>::type>::type , float>)); std::cout << deref_data(begin(j)) << std::endl; std::cout << deref_data(fusion::next(begin(j))) << std::endl; std::cout << deref_data(fusion::next(fusion::next(begin(j)))) << std::endl; BOOST_TEST((deref_data(begin(j)) == 0)); BOOST_TEST((deref_data(fusion::next(begin(j))) == "foo")); BOOST_TEST((deref_data(fusion::next(fusion::next(begin(j)))) == 1.3f)); } return boost::report_errors(); }