]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/tuple/test/another_tuple_test_bench.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / tuple / test / another_tuple_test_bench.cpp
1 // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6
7 // For more information, see http://www.boost.org
8
9
10 // another_test_bench.cpp --------------------------------
11
12 // This file has various tests to see that things that shouldn't
13 // compile, don't compile.
14
15 // Defining any of E1 to E5 or E7 to E11 opens some illegal code that
16 // should cause the compliation to fail.
17
18 #define BOOST_INCLUDE_MAIN // for testing, include rather than link
19 #include <boost/test/test_tools.hpp> // see "Header Implementation Option"
20
21 #include "boost/tuple/tuple.hpp"
22
23 #include <string>
24 #include <utility>
25
26 using namespace boost;
27 using namespace boost::tuples;
28
29
30 template<class T> void dummy(const T&) {}
31
32 class A {}; class B {}; class C {};
33
34 // A non-copyable class
35 class no_copy {
36 no_copy(const no_copy&) {}
37 public:
38 no_copy() {};
39 };
40
41 no_copy y;
42
43 #ifdef E1
44 tuple<no_copy> v1; // should faild
45 #endif
46
47
48 #ifdef E2
49 char cs[10];
50 tuple<char[10]> v3; // should fail, arrays must be stored as references
51 #endif
52
53 // a class without a public default constructor
54 class no_def_constructor {
55 no_def_constructor() {}
56 public:
57 no_def_constructor(std::string) {} // can be constructed with a string
58 };
59
60 void foo1() {
61
62 #ifdef E3
63 dummy(tuple<no_def_constructor, no_def_constructor, no_def_constructor>());
64 // should fail
65
66 #endif
67 }
68
69 void foo2() {
70 // testing default values
71 #ifdef E4
72 dummy(tuple<double&>()); // should fail, not defaults for references
73 dummy(tuple<const double&>()); // likewise
74 #endif
75
76 #ifdef E5
77 double dd = 5;
78 dummy(tuple<double&>(dd+3.14)); // should fail, temporary to non-const reference
79 #endif
80 }
81
82
83
84 // make_tuple ------------------------------------------
85
86
87 void foo3() {
88 #ifdef E7
89 std::make_pair("Doesn't","Work"); // fails
90 #endif
91 // make_tuple("Does", "Work"); // this should work
92 }
93
94
95
96 // - testing element access
97
98 void foo4()
99 {
100 double d = 2.7;
101 A a;
102 tuple<int, double&, const A&> t(1, d, a);
103 const tuple<int, double&, const A> ct = t;
104 (void)ct;
105 #ifdef E8
106 get<0>(ct) = 5; // can't assign to const
107 #endif
108
109 #ifdef E9
110 get<4>(t) = A(); // can't assign to const
111 #endif
112 #ifdef E10
113 dummy(get<5>(ct)); // illegal index
114 #endif
115 }
116
117 // testing copy and assignment with implicit conversions between elements
118 // testing tie
119
120 class AA {};
121 class BB : public AA {};
122 struct CC { CC() {} CC(const BB& b) {} };
123 struct DD { operator CC() const { return CC(); }; };
124
125 void foo5() {
126 tuple<char, BB*, BB, DD> t;
127 (void)t;
128 tuple<char, char> aaa;
129 tuple<int, int> bbb(aaa);
130 (void)bbb;
131 // tuple<int, AA*, CC, CC> a = t;
132 // a = t;
133 }
134
135
136 // testing tie
137 // testing assignment from std::pair
138 void foo7() {
139
140 tuple<int, int, float> a;
141 #ifdef E11
142 a = std::make_pair(1, 2); // should fail, tuple is of length 3, not 2
143 #endif
144
145 dummy(a);
146 }
147
148
149
150 // --------------------------------
151 // ----------------------------
152 int test_main(int, char *[]) {
153
154 foo1();
155 foo2();
156 foo3();
157 foo4();
158 foo5();
159
160 foo7();
161
162 return 0;
163 }