1//
2// bind_noexcept_mf2_test.cpp - noexcept member functions w/ the type<> syntax
3//
4// Copyright 2017 Peter Dimov
5//
6// Distributed under the Boost Software License, Version 1.0.
7// See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9//
10
11#include <boost/bind/bind.hpp>
12#include <boost/ref.hpp>
13#include <boost/core/lightweight_test.hpp>
14#include <boost/config.hpp>
15
16#if defined(BOOST_NO_CXX11_NOEXCEPT)
17
18int main()
19{
20}
21
22#else
23
24//
25
26struct X
27{
28 mutable unsigned int hash;
29
30 X(): hash(0) {}
31
32 int f0() noexcept { f1(a1: 17); return 0; }
33 int g0() const noexcept { g1(a1: 17); return 0; }
34
35 int f1(int a1) noexcept { hash = (hash * 17041 + a1) % 32768; return 0; }
36 int g1(int a1) const noexcept { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
37
38 int f2(int a1, int a2) noexcept { f1(a1); f1(a1: a2); return 0; }
39 int g2(int a1, int a2) const noexcept { g1(a1); g1(a1: a2); return 0; }
40
41 int f3(int a1, int a2, int a3) noexcept { f2(a1, a2); f1(a1: a3); return 0; }
42 int g3(int a1, int a2, int a3) const noexcept { g2(a1, a2); g1(a1: a3); return 0; }
43
44 int f4(int a1, int a2, int a3, int a4) noexcept { f3(a1, a2, a3); f1(a1: a4); return 0; }
45 int g4(int a1, int a2, int a3, int a4) const noexcept { g3(a1, a2, a3); g1(a1: a4); return 0; }
46
47 int f5(int a1, int a2, int a3, int a4, int a5) noexcept { f4(a1, a2, a3, a4); f1(a1: a5); return 0; }
48 int g5(int a1, int a2, int a3, int a4, int a5) const noexcept { g4(a1, a2, a3, a4); g1(a1: a5); return 0; }
49
50 int f6(int a1, int a2, int a3, int a4, int a5, int a6) noexcept { f5(a1, a2, a3, a4, a5); f1(a1: a6); return 0; }
51 int g6(int a1, int a2, int a3, int a4, int a5, int a6) const noexcept { g5(a1, a2, a3, a4, a5); g1(a1: a6); return 0; }
52
53 int f7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) noexcept { f6(a1, a2, a3, a4, a5, a6); f1(a1: a7); return 0; }
54 int g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const noexcept { g6(a1, a2, a3, a4, a5, a6); g1(a1: a7); return 0; }
55
56 int f8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) noexcept { f7(a1, a2, a3, a4, a5, a6, a7); f1(a1: a8); return 0; }
57 int g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const noexcept { g7(a1, a2, a3, a4, a5, a6, a7); g1(a1: a8); return 0; }
58};
59
60void member_function_test()
61{
62 X x;
63
64 // 0
65
66 boost::bind(boost::type<void>(), f: &X::f0, a1: &x)();
67 boost::bind(boost::type<void>(), f: &X::f0, a1: boost::ref(t&: x))();
68
69 boost::bind(boost::type<void>(), f: &X::g0, a1: &x)();
70 boost::bind(boost::type<void>(), f: &X::g0, a1: x)();
71 boost::bind(boost::type<void>(), f: &X::g0, a1: boost::ref(t&: x))();
72
73 // 1
74
75 boost::bind(boost::type<void>(), f: &X::f1, a1: &x, a2: 1)();
76 boost::bind(boost::type<void>(), f: &X::f1, a1: boost::ref(t&: x), a2: 1)();
77
78 boost::bind(boost::type<void>(), f: &X::g1, a1: &x, a2: 1)();
79 boost::bind(boost::type<void>(), f: &X::g1, a1: x, a2: 1)();
80 boost::bind(boost::type<void>(), f: &X::g1, a1: boost::ref(t&: x), a2: 1)();
81
82 // 2
83
84 boost::bind(boost::type<void>(), f: &X::f2, a1: &x, a2: 1, a3: 2)();
85 boost::bind(boost::type<void>(), f: &X::f2, a1: boost::ref(t&: x), a2: 1, a3: 2)();
86
87 boost::bind(boost::type<void>(), f: &X::g2, a1: &x, a2: 1, a3: 2)();
88 boost::bind(boost::type<void>(), f: &X::g2, a1: x, a2: 1, a3: 2)();
89 boost::bind(boost::type<void>(), f: &X::g2, a1: boost::ref(t&: x), a2: 1, a3: 2)();
90
91 // 3
92
93 boost::bind(boost::type<void>(), f: &X::f3, a1: &x, a2: 1, a3: 2, a4: 3)();
94 boost::bind(boost::type<void>(), f: &X::f3, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3)();
95
96 boost::bind(boost::type<void>(), f: &X::g3, a1: &x, a2: 1, a3: 2, a4: 3)();
97 boost::bind(boost::type<void>(), f: &X::g3, a1: x, a2: 1, a3: 2, a4: 3)();
98 boost::bind(boost::type<void>(), f: &X::g3, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3)();
99
100 // 4
101
102 boost::bind(boost::type<void>(), f: &X::f4, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4)();
103 boost::bind(boost::type<void>(), f: &X::f4, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4)();
104
105 boost::bind(boost::type<void>(), f: &X::g4, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4)();
106 boost::bind(boost::type<void>(), f: &X::g4, a1: x, a2: 1, a3: 2, a4: 3, a5: 4)();
107 boost::bind(boost::type<void>(), f: &X::g4, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4)();
108
109 // 5
110
111 boost::bind(boost::type<void>(), f: &X::f5, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5)();
112 boost::bind(boost::type<void>(), f: &X::f5, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5)();
113
114 boost::bind(boost::type<void>(), f: &X::g5, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5)();
115 boost::bind(boost::type<void>(), f: &X::g5, a1: x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5)();
116 boost::bind(boost::type<void>(), f: &X::g5, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5)();
117
118 // 6
119
120 boost::bind(boost::type<void>(), f: &X::f6, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6)();
121 boost::bind(boost::type<void>(), f: &X::f6, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6)();
122
123 boost::bind(boost::type<void>(), f: &X::g6, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6)();
124 boost::bind(boost::type<void>(), f: &X::g6, a1: x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6)();
125 boost::bind(boost::type<void>(), f: &X::g6, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6)();
126
127 // 7
128
129 boost::bind(boost::type<void>(), f: &X::f7, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)();
130 boost::bind(boost::type<void>(), f: &X::f7, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)();
131
132 boost::bind(boost::type<void>(), f: &X::g7, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)();
133 boost::bind(boost::type<void>(), f: &X::g7, a1: x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)();
134 boost::bind(boost::type<void>(), f: &X::g7, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7)();
135
136 // 8
137
138 boost::bind(boost::type<void>(), f: &X::f8, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8)();
139 boost::bind(boost::type<void>(), f: &X::f8, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8)();
140
141 boost::bind(boost::type<void>(), f: &X::g8, a1: &x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8)();
142 boost::bind(boost::type<void>(), f: &X::g8, a1: x, a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8)();
143 boost::bind(boost::type<void>(), f: &X::g8, a1: boost::ref(t&: x), a2: 1, a3: 2, a4: 3, a5: 4, a6: 5, a7: 6, a8: 7, a9: 8)();
144
145 BOOST_TEST( x.hash == 23558 );
146}
147
148int main()
149{
150 member_function_test();
151 return boost::report_errors();
152}
153
154#endif
155

source code of boost/libs/bind/test/bind_noexcept_mf2_test.cpp