1 /*=============================================================================
2     Copyright (c) 1999-2003 Jaakko Jarvi
3     Copyright (c) 2001-2011 Joel de Guzman
4     Copyright (c) 2006 Dan Marsden
5 
6     Distributed under the Boost Software License, Version 1.0. (See accompanying
7     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 ==============================================================================*/
9 #include <boost/fusion/container/map/map.hpp>
10 #include <boost/fusion/container/generation/make_map.hpp>
11 #include <boost/fusion/container/generation/map_tie.hpp>
12 #include <boost/detail/lightweight_test.hpp>
13 #include <boost/fusion/sequence/intrinsic/at.hpp>
14 #include <boost/fusion/mpl.hpp>
15 #include <boost/preprocessor/cat.hpp>
16 #include <boost/mpl/insert_range.hpp>
17 #include <boost/mpl/vector.hpp>
18 #include <boost/mpl/begin.hpp>
19 #include <boost/mpl/equal.hpp>
20 #include <boost/static_assert.hpp>
21 #include <string>
22 
23 struct k1 {};
24 struct k2 {};
25 struct k3 {};
26 struct k4 {};
27 
28 namespace test_detail
29 {
30     // classes with different kinds of conversions
31     class AA {};
32     class BB : public AA {};
CCtest_detail::CC33     struct CC { CC() {} CC(const BB&) {} };
operator CCtest_detail::DD34     struct DD { operator CC() const { return CC(); }; };
35 }
36 
37 boost::fusion::map<
38     boost::fusion::pair<k1, double>,
39     boost::fusion::pair<k2, double>,
40     boost::fusion::pair<k3, double>,
41     boost::fusion::pair<k4, double>
42 >
foo(int i)43 foo(int i)
44 {
45    return boost::fusion::make_map<k1, k2, k3, k4>(i, i+1, i+2, i+3);
46 }
47 
48 void
test()49 test()
50 {
51     using namespace boost::fusion;
52     using namespace test_detail;
53 
54     map<pair<k1, int>, pair<k2, char> > t1(4, 'a');
55     map<pair<k1, int>, pair<k2, char> > t2(5, 'b');
56     t2 = t1;
57     BOOST_TEST(at_c<0>(t1).second == at_c<0>(t2).second);
58     BOOST_TEST(at_c<1>(t1).second == at_c<1>(t2).second);
59 
60     map<pair<k1, int>, pair<k2, char const*> > t4(4, "a");
61     map<pair<k1, long>, pair<k2, std::string> > t3(2, std::string("a"));
62     t3 = t4;
63     BOOST_TEST((double)at_c<0>(t4).second == at_c<0>(t3).second);
64     BOOST_TEST(at_c<1>(t4).second == at_c<1>(t3).second);
65 
66     // testing copy and assignment with implicit conversions
67     // between elements testing tie
68 
69     map<pair<k1, char>, pair<k2, BB*>, pair<k3, BB>, pair<k4, DD> > t;
70     map<pair<k1, int>, pair<k2, AA*>, pair<k3, CC>, pair<k4, CC> > a(t);
71     a = t;
72 
73     int i; char c; double d;
74     map_tie<k1, k2, k3>(i, c, d) = make_map<k1, k2, k3>(1, 'a', 5.5);
75 
76     BOOST_TEST(i==1);
77     BOOST_TEST(c=='a');
78     BOOST_TEST(d>5.4 && d<5.6);
79 
80     // returning a map with conversion
81     foo(2);
82 }
83 
84 int
main()85 main()
86 {
87     test();
88     return boost::report_errors();
89 }
90 
91