Made map random access. Thanks to Brandon Kohn!

[SVN r74882]
This commit is contained in:
Joel de Guzman
2011-10-10 09:55:52 +00:00
parent b6df98e86c
commit 10274e7884
5 changed files with 73 additions and 9 deletions

View File

@ -6,6 +6,7 @@
==============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/fusion/container/vector/vector.hpp>
#include <boost/fusion/container/map/map.hpp>
#include <boost/fusion/adapted/mpl.hpp>
#include <boost/fusion/sequence/io/out.hpp>
#include <boost/fusion/container/generation/make_vector.hpp>
@ -82,6 +83,27 @@ main()
));
}
//! Map
{
typedef pair<boost::mpl::int_<0>, std::string> pair0;
typedef pair<boost::mpl::int_<1>, std::string> pair1;
typedef pair<boost::mpl::int_<2>, std::string> pair2;
typedef pair<boost::mpl::int_<3>, std::string> pair3;
typedef pair<boost::mpl::int_<4>, std::string> pair4;
typedef map< pair0, pair1, pair2, pair3, pair4 > map_type;
map_type m( pair0("zero"), pair1("one"), pair2("two"), pair3("three"), pair4("four") );
typedef reverse_view<map_type> view_type;
view_type rev(m);
std::cout << rev << std::endl;
BOOST_TEST((rev == make_vector( pair4("four"), pair3("three"), pair2("two"), pair1("one"), pair0("zero"))));
BOOST_TEST((at_c<0>(rev) == pair4("four")));
BOOST_TEST((at_c<1>(rev) == pair3("three")));
BOOST_TEST((at_c<2>(rev) == pair2("two")));
BOOST_TEST((at_c<3>(rev) == pair1("one")));
BOOST_TEST((at_c<4>(rev) == pair0("zero")));
}
return boost::report_errors();
}