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#include "boost/tuple/tuple.hpp"
19
20#include "boost/core/lightweight_test.hpp"
21
22#include <string>
23#include <utility>
24
25using namespace boost;
26using namespace boost::tuples;
27
28
29template<class T> void dummy(const T&) {}
30
31class A {}; class B {}; class C {};
32
33// A non-copyable class
34class no_copy {
35 no_copy(const no_copy&) {}
36public:
37 no_copy() {};
38};
39
40no_copy y;
41
42#ifdef E1
43tuple<no_copy> v1; // should faild
44#endif
45
46
47#ifdef E2
48char cs[10];
49tuple<char[10]> v3; // should fail, arrays must be stored as references
50#endif
51
52// a class without a public default constructor
53class no_def_constructor {
54 no_def_constructor() {}
55public:
56 no_def_constructor(std::string) {} // can be constructed with a string
57};
58
59void foo1() {
60
61#ifdef E3
62 dummy(tuple<no_def_constructor, no_def_constructor, no_def_constructor>());
63 // should fail
64
65#endif
66}
67
68void foo2() {
69// testing default values
70#ifdef E4
71 dummy(tuple<double&>()); // should fail, not defaults for references
72 dummy(tuple<const double&>()); // likewise
73#endif
74
75#ifdef E5
76 double dd = 5;
77 dummy(tuple<double&>(dd+3.14)); // should fail, temporary to non-const reference
78#endif
79}
80
81
82
83// make_tuple ------------------------------------------
84
85
86 void foo3() {
87#ifdef E7
88 std::make_pair("Doesn't","Work"); // fails
89#endif
90 // make_tuple("Does", "Work"); // this should work
91}
92
93
94
95// - testing element access
96
97void foo4()
98{
99 double d = 2.7;
100 A a;
101 tuple<int, double&, const A&> t(1, d, a);
102 const tuple<int, double&, const A> ct = t;
103 (void)ct;
104#ifdef E8
105 get<0>(ct) = 5; // can't assign to const
106#endif
107
108#ifdef E9
109 get<4>(t) = A(); // can't assign to const
110#endif
111#ifdef E10
112 dummy(get<5>(ct)); // illegal index
113#endif
114}
115
116// testing copy and assignment with implicit conversions between elements
117// testing tie
118
119 class AA {};
120 class BB : public AA {};
121 struct CC { CC() {} CC(const BB& b) {} };
122 struct DD { operator CC() const { return CC(); }; };
123
124 void foo5() {
125 tuple<char, BB*, BB, DD> t;
126 (void)t;
127 tuple<char, char> aaa;
128 tuple<int, int> bbb(aaa);
129 (void)bbb;
130 // tuple<int, AA*, CC, CC> a = t;
131 // a = t;
132 }
133
134
135// testing tie
136// testing assignment from std::pair
137void foo7() {
138
139 tuple<int, int, float> a;
140#ifdef E11
141 a = std::make_pair(1, 2); // should fail, tuple is of length 3, not 2
142#endif
143
144 dummy(a);
145}
146
147
148
149// --------------------------------
150// ----------------------------
151int main() {
152
153 foo1();
154 foo2();
155 foo3();
156 foo4();
157 foo5();
158
159 foo7();
160
161 return boost::report_errors();
162}
163

source code of boost/libs/tuple/test/another_tuple_test_bench.cpp