1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // |
3 | // (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost |
4 | // Software License, Version 1.0. (See accompanying file |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | // |
7 | // See http://www.boost.org/libs/container for documentation. |
8 | // |
9 | ////////////////////////////////////////////////////////////////////////////// |
10 | #include <boost/container/detail/pair.hpp> |
11 | #include "movable_int.hpp" |
12 | #include "emplace_test.hpp" |
13 | #include<boost/move/utility_core.hpp> |
14 | #include<boost/move/detail/fwd_macros.hpp> |
15 | #include<boost/core/lightweight_test.hpp> |
16 | |
17 | //non_copymovable_int |
18 | //copyable_int |
19 | //movable_int |
20 | //movable_and_copyable_int |
21 | |
22 | |
23 | #include <boost/tuple/tuple.hpp> |
24 | |
25 | #if !defined(BOOST_NO_CXX11_HDR_TUPLE) || (defined(BOOST_MSVC) && (BOOST_MSVC == 1700 || BOOST_MSVC == 1600)) |
26 | #define |
27 | #endif |
28 | |
29 | #if defined(BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE) |
30 | #include <tuple> |
31 | #endif |
32 | |
33 | using namespace ::boost::container; |
34 | |
35 | int main () |
36 | { |
37 | { |
38 | dtl::pair<test::non_copymovable_int, test::non_copymovable_int> p1; |
39 | dtl::pair<test::copyable_int, test::copyable_int> p2; |
40 | dtl::pair<test::movable_int, test::movable_int> p3; |
41 | dtl::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> p4; |
42 | } |
43 | { //Constructible from two values |
44 | dtl::pair<test::non_copymovable_int, test::non_copymovable_int> p1(1, 2); |
45 | dtl::pair<test::copyable_int, test::copyable_int> p2(1, 2); |
46 | dtl::pair<test::movable_int, test::movable_int> p3(1, 2); |
47 | dtl::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> p4(1, 2); |
48 | } |
49 | |
50 | { //Constructible from internal types |
51 | dtl::pair<test::copyable_int, test::copyable_int> p2(test::copyable_int(1), test::copyable_int(2)); |
52 | { |
53 | test::movable_int a(1), b(2); |
54 | dtl::pair<test::movable_int, test::movable_int> p3(::boost::move(t&: a), ::boost::move(t&: b)); |
55 | } |
56 | { |
57 | test::movable_and_copyable_int a(1), b(2); |
58 | dtl::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> p4(::boost::move(t&: a), ::boost::move(t&: b)); |
59 | } |
60 | } |
61 | { //piecewise construct from boost tuple |
62 | using namespace boost::tuples; |
63 | { |
64 | boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<>(), tuple<>()); |
65 | BOOST_TEST(p.first == 0); |
66 | BOOST_TEST(p.second == 0.f); |
67 | } |
68 | { |
69 | boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<>(), tuple<float>(2.f)); |
70 | BOOST_TEST(p.first == 0); |
71 | BOOST_TEST(p.second == 2.f); |
72 | } |
73 | { |
74 | boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<int>(2), tuple<float>(1.f)); |
75 | BOOST_TEST(p.first == 2); |
76 | BOOST_TEST(p.second == 1.f); |
77 | } |
78 | { |
79 | boost::container::dtl::pair |
80 | < boost::container::dtl::pair<int, float> |
81 | , boost::container::dtl::pair<double, char> |
82 | > p(piecewise_construct, tuple<int, float>(3, 4.f), tuple<double, char>(8.,'a')); |
83 | BOOST_TEST(p.first.first == 3); |
84 | BOOST_TEST(p.first.second == 4.f); |
85 | BOOST_TEST(p.second.first == 8.); |
86 | BOOST_TEST(p.second.second == 'a'); |
87 | } |
88 | { |
89 | boost::container::dtl::pair |
90 | < tuple<int, float, double> |
91 | , char |
92 | > p(piecewise_construct, tuple<int, float, double>(3, 16.f, 32.), tuple<char>('b')); |
93 | BOOST_TEST(p.first.get<0>() == 3); |
94 | BOOST_TEST(p.first.get<1>() == 16.f); |
95 | BOOST_TEST(p.first.get<2>() == 32.); |
96 | BOOST_TEST(p.second == 'b'); |
97 | } |
98 | } |
99 | #if defined(BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE) |
100 | { //piecewise construct from std tuple |
101 | using std::tuple; |
102 | { |
103 | boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<>(), tuple<>()); |
104 | BOOST_TEST(p.first == 0); |
105 | BOOST_TEST(p.second == 0.f); |
106 | } |
107 | { |
108 | boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<>(), tuple<float>(2.f)); |
109 | BOOST_TEST(p.first == 0); |
110 | BOOST_TEST(p.second == 2.f); |
111 | } |
112 | { |
113 | boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<int>(2), tuple<float>(1.f)); |
114 | BOOST_TEST(p.first == 2); |
115 | BOOST_TEST(p.second == 1.f); |
116 | } |
117 | { |
118 | boost::container::dtl::pair |
119 | < boost::container::dtl::pair<int, float> |
120 | , boost::container::dtl::pair<double, char> |
121 | > p(piecewise_construct, tuple<int, float>(3, 4.f), tuple<double, char>(8.,'a')); |
122 | BOOST_TEST(p.first.first == 3); |
123 | BOOST_TEST(p.first.second == 4.f); |
124 | BOOST_TEST(p.second.first == 8.); |
125 | BOOST_TEST(p.second.second == 'a'); |
126 | } |
127 | { |
128 | boost::container::dtl::pair |
129 | < tuple<int, float, double> |
130 | , char |
131 | > p(piecewise_construct, tuple<int, float, double>(3, 16.f, 32.), tuple<char>('b')); |
132 | BOOST_TEST(std::get<0>(p.first) == 3); |
133 | BOOST_TEST(std::get<1>(p.first) == 16.f); |
134 | BOOST_TEST(std::get<2>(p.first) == 32.); |
135 | BOOST_TEST(p.second == 'b'); |
136 | } |
137 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) |
138 | typedef dtl::pair<test::movable_int, test::movable_int> movable_pair_t; |
139 | typedef dtl::pair<movable_pair_t, movable_pair_t> movable_pair_pair_t; |
140 | test::movable_int a(1), b(2), c(3), d(4); |
141 | movable_pair_pair_t p( piecewise_construct |
142 | , dtl::forward_as_tuple_impl(values: boost::move(t&: a), values: boost::move(t&: b)) |
143 | , dtl::forward_as_tuple_impl(values: boost::move(t&: c), values: boost::move(t&: d)) |
144 | ); |
145 | BOOST_TEST(p.first.first == 1); |
146 | BOOST_TEST(p.first.second == 2); |
147 | BOOST_TEST(p.second.first == 3); |
148 | BOOST_TEST(p.second.second == 4); |
149 | #endif |
150 | } |
151 | #endif //#!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_HDR_TUPLE) |
152 | return ::boost::report_errors(); |
153 | } |
154 | |