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 154
|
//
// bind_noexcept_mf2_test.cpp - noexcept member functions w/ the type<> syntax
//
// Copyright 2017 Peter Dimov
//
// 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)
//
#include <boost/bind/bind.hpp>
#include <boost/ref.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config.hpp>
#if defined(BOOST_NO_CXX11_NOEXCEPT)
int main()
{
}
#else
//
struct X
{
mutable unsigned int hash;
X(): hash(0) {}
int f0() noexcept { f1(17); return 0; }
int g0() const noexcept { g1(17); return 0; }
int f1(int a1) noexcept { hash = (hash * 17041 + a1) % 32768; return 0; }
int g1(int a1) const noexcept { hash = (hash * 17041 + a1 * 2) % 32768; return 0; }
int f2(int a1, int a2) noexcept { f1(a1); f1(a2); return 0; }
int g2(int a1, int a2) const noexcept { g1(a1); g1(a2); return 0; }
int f3(int a1, int a2, int a3) noexcept { f2(a1, a2); f1(a3); return 0; }
int g3(int a1, int a2, int a3) const noexcept { g2(a1, a2); g1(a3); return 0; }
int f4(int a1, int a2, int a3, int a4) noexcept { f3(a1, a2, a3); f1(a4); return 0; }
int g4(int a1, int a2, int a3, int a4) const noexcept { g3(a1, a2, a3); g1(a4); return 0; }
int f5(int a1, int a2, int a3, int a4, int a5) noexcept { f4(a1, a2, a3, a4); f1(a5); return 0; }
int g5(int a1, int a2, int a3, int a4, int a5) const noexcept { g4(a1, a2, a3, a4); g1(a5); return 0; }
int f6(int a1, int a2, int a3, int a4, int a5, int a6) noexcept { f5(a1, a2, a3, a4, a5); f1(a6); return 0; }
int g6(int a1, int a2, int a3, int a4, int a5, int a6) const noexcept { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
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(a7); return 0; }
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(a7); return 0; }
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(a8); return 0; }
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(a8); return 0; }
};
void member_function_test()
{
X x;
// 0
boost::bind(boost::type<void>(), &X::f0, &x)();
boost::bind(boost::type<void>(), &X::f0, boost::ref(x))();
boost::bind(boost::type<void>(), &X::g0, &x)();
boost::bind(boost::type<void>(), &X::g0, x)();
boost::bind(boost::type<void>(), &X::g0, boost::ref(x))();
// 1
boost::bind(boost::type<void>(), &X::f1, &x, 1)();
boost::bind(boost::type<void>(), &X::f1, boost::ref(x), 1)();
boost::bind(boost::type<void>(), &X::g1, &x, 1)();
boost::bind(boost::type<void>(), &X::g1, x, 1)();
boost::bind(boost::type<void>(), &X::g1, boost::ref(x), 1)();
// 2
boost::bind(boost::type<void>(), &X::f2, &x, 1, 2)();
boost::bind(boost::type<void>(), &X::f2, boost::ref(x), 1, 2)();
boost::bind(boost::type<void>(), &X::g2, &x, 1, 2)();
boost::bind(boost::type<void>(), &X::g2, x, 1, 2)();
boost::bind(boost::type<void>(), &X::g2, boost::ref(x), 1, 2)();
// 3
boost::bind(boost::type<void>(), &X::f3, &x, 1, 2, 3)();
boost::bind(boost::type<void>(), &X::f3, boost::ref(x), 1, 2, 3)();
boost::bind(boost::type<void>(), &X::g3, &x, 1, 2, 3)();
boost::bind(boost::type<void>(), &X::g3, x, 1, 2, 3)();
boost::bind(boost::type<void>(), &X::g3, boost::ref(x), 1, 2, 3)();
// 4
boost::bind(boost::type<void>(), &X::f4, &x, 1, 2, 3, 4)();
boost::bind(boost::type<void>(), &X::f4, boost::ref(x), 1, 2, 3, 4)();
boost::bind(boost::type<void>(), &X::g4, &x, 1, 2, 3, 4)();
boost::bind(boost::type<void>(), &X::g4, x, 1, 2, 3, 4)();
boost::bind(boost::type<void>(), &X::g4, boost::ref(x), 1, 2, 3, 4)();
// 5
boost::bind(boost::type<void>(), &X::f5, &x, 1, 2, 3, 4, 5)();
boost::bind(boost::type<void>(), &X::f5, boost::ref(x), 1, 2, 3, 4, 5)();
boost::bind(boost::type<void>(), &X::g5, &x, 1, 2, 3, 4, 5)();
boost::bind(boost::type<void>(), &X::g5, x, 1, 2, 3, 4, 5)();
boost::bind(boost::type<void>(), &X::g5, boost::ref(x), 1, 2, 3, 4, 5)();
// 6
boost::bind(boost::type<void>(), &X::f6, &x, 1, 2, 3, 4, 5, 6)();
boost::bind(boost::type<void>(), &X::f6, boost::ref(x), 1, 2, 3, 4, 5, 6)();
boost::bind(boost::type<void>(), &X::g6, &x, 1, 2, 3, 4, 5, 6)();
boost::bind(boost::type<void>(), &X::g6, x, 1, 2, 3, 4, 5, 6)();
boost::bind(boost::type<void>(), &X::g6, boost::ref(x), 1, 2, 3, 4, 5, 6)();
// 7
boost::bind(boost::type<void>(), &X::f7, &x, 1, 2, 3, 4, 5, 6, 7)();
boost::bind(boost::type<void>(), &X::f7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)();
boost::bind(boost::type<void>(), &X::g7, &x, 1, 2, 3, 4, 5, 6, 7)();
boost::bind(boost::type<void>(), &X::g7, x, 1, 2, 3, 4, 5, 6, 7)();
boost::bind(boost::type<void>(), &X::g7, boost::ref(x), 1, 2, 3, 4, 5, 6, 7)();
// 8
boost::bind(boost::type<void>(), &X::f8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(boost::type<void>(), &X::f8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(boost::type<void>(), &X::g8, &x, 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(boost::type<void>(), &X::g8, x, 1, 2, 3, 4, 5, 6, 7, 8)();
boost::bind(boost::type<void>(), &X::g8, boost::ref(x), 1, 2, 3, 4, 5, 6, 7, 8)();
BOOST_TEST( x.hash == 23558 );
}
int main()
{
member_function_test();
return boost::report_errors();
}
#endif
|