/*============================================================================= 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 namespace ns { struct x_member; struct y_member; struct z_member; struct point { int x; int y; }; } BOOST_FUSION_ADAPT_ASSOC_STRUCT( ns::point, (int, x, ns::x_member) (int, y, ns::y_member) ) int main() { using namespace boost::fusion; using namespace boost; std::cout << tuple_open('['); std::cout << tuple_close(']'); std::cout << tuple_delimiter(", "); { ns::point p = {123, 456}; std::cout << as_map(p) << std::endl; } { ns::point p = {123, 456}; boost::fusion::result_of::as_map::type map(p); std::cout << at_key(map) << std::endl; std::cout << at_key(map) << std::endl; BOOST_TEST(at_key(map) == 123); BOOST_TEST(at_key(map) == 456); } { boost::fusion::result_of::as_map >::type map(make_set(1, '2')); BOOST_TEST(at_key(map) == 1); BOOST_TEST(at_key(map) == '2'); } { // test conversion typedef map< pair , pair > map_type; ns::point p = {123, 456}; map_type m(p); BOOST_TEST(as_vector(m) == make_vector(make_pair(123), make_pair(456))); m = (make_vector(make_pair(123), make_pair(456))); // test assign BOOST_TEST(as_vector(m) == make_vector(make_pair(123), make_pair(456))); } return boost::report_errors(); }