]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/fusion/test/sequence/map_construction.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / map_construction.cpp
CommitLineData
7c673cae
FG
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/detail/lightweight_test.hpp>
11#include <boost/fusion/sequence/intrinsic/at.hpp>
12
13struct key1 {};
14struct key2 {};
15struct key3 {};
16
17namespace test_detail
18{
19 // something to prevent warnings for unused variables
20 template<class T> void dummy(const T&) {}
21
22 // no public default constructor
23 class foo
24 {
25 public:
26
27 explicit foo(int v) : val(v) {}
28
29 bool operator==(const foo& other) const
30 {
31 return val == other.val;
32 }
33
34 private:
35
36 foo() {}
37 int val;
38 };
39
40 // another class without a public default constructor
41 class no_def_constructor
42 {
43 no_def_constructor() {}
44
45 public:
46
47 no_def_constructor(std::string) {}
48 };
49}
50
51inline void
52test()
53{
54 using namespace boost::fusion;
55 using namespace test_detail;
56
57 nil empty;
92f5a8d4 58 (void)empty;
7c673cae
FG
59
60 map<> empty0;
92f5a8d4 61 (void)empty0;
7c673cae
FG
62
63#ifndef NO_CONSTRUCT_FROM_NIL
64 map<> empty1(empty);
92f5a8d4 65 (void)empty1;
7c673cae
FG
66#endif
67
68 map<pair<key1, int> > t1;
69 BOOST_TEST(at_c<0>(t1).second == int());
70
71 map<pair<key1, float> > t2(5.5f);
72 BOOST_TEST(at_c<0>(t2).second > 5.4f && at_c<0>(t2).second < 5.6f);
73
74 map<pair<key1, foo> > t3(foo(12));
75 BOOST_TEST(at_c<0>(t3).second == foo(12));
76
77 map<pair<key1, double> > t4(t2);
78 BOOST_TEST(at_c<0>(t4).second > 5.4 && at_c<0>(t4).second < 5.6);
79
80 map<pair<key1, int>, pair<key2, float> > t5;
81 BOOST_TEST(at_c<0>(t5).second == int());
82 BOOST_TEST(at_c<1>(t5).second == float());
83
84 map<pair<key1, int>, pair<key2, float> > t6(12, 5.5f);
85 BOOST_TEST(at_c<0>(t6).second == 12);
86 BOOST_TEST(at_c<1>(t6).second > 5.4f && at_c<1>(t6).second < 5.6f);
87
88 map<pair<key1, int>, pair<key2, float> > t7(t6);
89 BOOST_TEST(at_c<0>(t7).second == 12);
90 BOOST_TEST(at_c<1>(t7).second > 5.4f && at_c<1>(t7).second < 5.6f);
91
92 map<pair<key1, long>, pair<key2, double> > t8(t6);
93 BOOST_TEST(at_c<0>(t8).second == 12);
94 BOOST_TEST(at_c<1>(t8).second > 5.4f && at_c<1>(t8).second < 5.6f);
95
96 dummy
97 (
98 map<
99 pair<key1, no_def_constructor>,
100 pair<key2, no_def_constructor>,
101 pair<key3, no_def_constructor> >
102 (
103 pair<key1, no_def_constructor>(std::string("Jaba")), // ok, since the default
104 pair<key2, no_def_constructor>(std::string("Daba")), // constructor is not used
105 pair<key3, no_def_constructor>(std::string("Doo"))
106 )
107 );
108
109 dummy(map<pair<key1, int>, pair<key2, double> >());
110 dummy(map<pair<key1, int>, pair<key2, double> >(1,3.14));
111
112#if defined(FUSION_TEST_FAIL)
113 dummy(map<pair<key1, double&> >()); // should fail, no defaults for references
114 dummy(map<pair<key1, const double&> >()); // likewise
115#endif
116
117 {
118 double dd = 5;
119 dummy(map<pair<key1, double&> >(pair<key1, double&>(dd))); // ok
120 dummy(map<pair<key1, const double&> >(pair<key1, const double&>(dd+3.14))); // ok, but dangerous
121 }
122
123#if defined(FUSION_TEST_FAIL)
124 dummy(map<pair<key1, double&> >(dd+3.14)); // should fail,
125 // temporary to non-const reference
126#endif
127}
128
129int
130main()
131{
132 test();
133 return boost::report_errors();
134}