Index: doc/container.qbk =================================================================== --- doc/container.qbk (revision 83330) +++ doc/container.qbk (working copy) @@ -1918,7 +1918,7 @@ [*Semantics]: Convert a fusion sequence, `seq`, to a __map__. -[*Precondition]: The elements of the sequence are assumed to be +[*Precondition]: For non-associative sequence, the elements are assumed to be __fusion_pair__s. There may be no duplicate __fusion_pair__ key types. [heading Header] @@ -1928,9 +1928,25 @@ [heading Example] + // from sequence of __fusion_pair__ as_map(__make_vector__( __fusion_make_pair__('X') , __fusion_make_pair__("Men"))) + + // from associative sequence + namespace ns + { + struct x_member; + struct y_member; + } + BOOST_FUSION_DEFINE_ASSOC_STRUCT( + (ns), + point, + (int, x, ns::x_member) + (int, y, ns::y_member) + ) + ... + as_map(ns::point(123, 456)) [endsect] @@ -2119,7 +2135,7 @@ [*Semantics]: Convert a fusion sequence, `Sequence`, to a __map__. -[*Precondition]: The elements of the sequence are assumed to be +[*Precondition]: For non-associative sequence, the elements are assumed to be __fusion_pair__s. There may be no duplicate __fusion_pair__ key types. [heading Header] @@ -2129,9 +2145,25 @@ [heading Example] + // from sequence of __fusion_pair__ result_of::as_map<__vector__< __fusion_pair__ , __fusion_pair__ > >::type + + // from associative sequence + namespace ns + { + struct x_member; + struct y_member; + } + BOOST_FUSION_DEFINE_ASSOC_STRUCT( + (ns), + point, + (int, x, ns::x_member) + (int, y, ns::y_member) + ) + ... + result_of::as_map::type // __map__<__fusion_pair__, __fusion_pair__ > [endsect] Index: test/Jamfile =================================================================== --- test/Jamfile (revision 83330) +++ test/Jamfile (working copy) @@ -57,6 +57,7 @@ [ run sequence/as_list.cpp : : : : ] [ run sequence/as_map.cpp : : : : ] + [ run sequence/as_map_assoc.cpp : : : : ] [ run sequence/as_set.cpp : : : : ] [ run sequence/as_vector.cpp : : : : ] [ run sequence/boost_tuple.cpp : : : : ] Index: test/sequence/as_map_assoc.cpp =================================================================== --- test/sequence/as_map_assoc.cpp (revision 0) +++ test/sequence/as_map_assoc.cpp (revision 0) @@ -0,0 +1,85 @@ +/*============================================================================= + 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(); +} +