File: pair_test.cpp

package info (click to toggle)
boost1.74 1.74.0%2Bds1-21
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 463,588 kB
  • sloc: cpp: 3,338,117; xml: 131,293; python: 33,088; ansic: 14,292; asm: 4,038; sh: 3,353; makefile: 1,193; perl: 1,036; yacc: 478; php: 212; ruby: 102; lisp: 24; sql: 13; csh: 6
file content (153 lines) | stat: -rw-r--r-- 6,063 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2011-2013. 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)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#include <boost/container/detail/pair.hpp>
#include "movable_int.hpp"
#include "emplace_test.hpp"
#include<boost/move/utility_core.hpp>
#include<boost/move/detail/fwd_macros.hpp>
#include<boost/core/lightweight_test.hpp>

//non_copymovable_int
//copyable_int
//movable_int
//movable_and_copyable_int


#include <boost/tuple/tuple.hpp>

#if !defined(BOOST_NO_CXX11_HDR_TUPLE) || (defined(BOOST_MSVC) && (BOOST_MSVC == 1700 || BOOST_MSVC == 1600))
#define BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE
#endif

#if defined(BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE)
#include <tuple>
#endif

using namespace ::boost::container;

int main ()
{
   {
      dtl::pair<test::non_copymovable_int, test::non_copymovable_int> p1;
      dtl::pair<test::copyable_int, test::copyable_int> p2;
      dtl::pair<test::movable_int, test::movable_int> p3;
      dtl::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> p4;
   }
   {  //Constructible from two values
      dtl::pair<test::non_copymovable_int, test::non_copymovable_int> p1(1, 2);
      dtl::pair<test::copyable_int, test::copyable_int> p2(1, 2);
      dtl::pair<test::movable_int, test::movable_int> p3(1, 2);
      dtl::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> p4(1, 2);
   }

   {  //Constructible from internal types
      dtl::pair<test::copyable_int, test::copyable_int> p2(test::copyable_int(1), test::copyable_int(2));
      {
         test::movable_int a(1), b(2);
         dtl::pair<test::movable_int, test::movable_int> p3(::boost::move(a), ::boost::move(b));
      }
      {
         test::movable_and_copyable_int a(1), b(2);
         dtl::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> p4(::boost::move(a), ::boost::move(b));
      }
   }
   {  //piecewise construct from boost tuple
      using namespace boost::tuples;
      {
         boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<>(), tuple<>());
         BOOST_TEST(p.first == 0);
         BOOST_TEST(p.second == 0.f);
      }
      {
         boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<>(), tuple<float>(2.f));
         BOOST_TEST(p.first == 0);
         BOOST_TEST(p.second == 2.f);
      }
      {
         boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<int>(2), tuple<float>(1.f));
         BOOST_TEST(p.first == 2);
         BOOST_TEST(p.second == 1.f);
      }
      {
         boost::container::dtl::pair
            < boost::container::dtl::pair<int, float>
            , boost::container::dtl::pair<double, char>
            > p(piecewise_construct, tuple<int, float>(3, 4.f), tuple<double, char>(8.,'a'));
         BOOST_TEST(p.first.first   == 3);
         BOOST_TEST(p.first.second  == 4.f);
         BOOST_TEST(p.second.first  == 8.);
         BOOST_TEST(p.second.second == 'a');
      }
      {
         boost::container::dtl::pair
            < tuple<int, float, double>
            , char
            > p(piecewise_construct, tuple<int, float, double>(3, 16.f, 32.), tuple<char>('b'));
         BOOST_TEST(p.first.get<0>() == 3);
         BOOST_TEST(p.first.get<1>() == 16.f);
         BOOST_TEST(p.first.get<2>() == 32.);
         BOOST_TEST(p.second == 'b');
      }
   }
   #if defined(BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE)
   {  //piecewise construct from std tuple
      using std::tuple;
      {
         boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<>(), tuple<>());
         BOOST_TEST(p.first == 0);
         BOOST_TEST(p.second == 0.f);
      }
      {
         boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<>(), tuple<float>(2.f));
         BOOST_TEST(p.first == 0);
         BOOST_TEST(p.second == 2.f);
      }
      {
         boost::container::dtl::pair<int, float> p(piecewise_construct, tuple<int>(2), tuple<float>(1.f));
         BOOST_TEST(p.first == 2);
         BOOST_TEST(p.second == 1.f);
      }
      {
         boost::container::dtl::pair
            < boost::container::dtl::pair<int, float>
            , boost::container::dtl::pair<double, char>
            > p(piecewise_construct, tuple<int, float>(3, 4.f), tuple<double, char>(8.,'a'));
         BOOST_TEST(p.first.first   == 3);
         BOOST_TEST(p.first.second  == 4.f);
         BOOST_TEST(p.second.first  == 8.);
         BOOST_TEST(p.second.second == 'a');
      }
      {
         boost::container::dtl::pair
            < tuple<int, float, double>
            , char
            > p(piecewise_construct, tuple<int, float, double>(3, 16.f, 32.), tuple<char>('b'));
         BOOST_TEST(std::get<0>(p.first) == 3);
         BOOST_TEST(std::get<1>(p.first) == 16.f);
         BOOST_TEST(std::get<2>(p.first) == 32.);
         BOOST_TEST(p.second == 'b');
      }
      #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
      typedef dtl::pair<test::movable_int, test::movable_int> movable_pair_t;
      typedef dtl::pair<movable_pair_t, movable_pair_t> movable_pair_pair_t;
      test::movable_int a(1), b(2), c(3), d(4);
      movable_pair_pair_t p( piecewise_construct
                           , dtl::forward_as_tuple_impl(boost::move(a), boost::move(b))
                           , dtl::forward_as_tuple_impl(boost::move(c), boost::move(d))
                           );
      BOOST_TEST(p.first.first   == 1);
      BOOST_TEST(p.first.second  == 2);
      BOOST_TEST(p.second.first  == 3);
      BOOST_TEST(p.second.second == 4);
      #endif
   }
   #endif   //#!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_HDR_TUPLE)
   return ::boost::report_errors();
}