]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/phoenix/test/boost_bind_compatibility/bind_void_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / phoenix / test / boost_bind_compatibility / bind_void_test.cpp
CommitLineData
7c673cae
FG
1#include <boost/config.hpp>
2
3#if defined(BOOST_MSVC)
4#pragma warning(disable: 4786) // identifier truncated in debug info
5#pragma warning(disable: 4710) // function not inlined
6#pragma warning(disable: 4711) // function selected for automatic inline expansion
7#pragma warning(disable: 4514) // unreferenced inline removed
8#endif
9
10//
11// bind_void_test.cpp - test for bind<void>
12//
13// Copyright (c) 2008 Peter Dimov
14// Copyright (c) 2014 Agustin Berge
15//
16// Distributed under the Boost Software License, Version 1.0. (See
17// accompanying file LICENSE_1_0.txt or copy at
18// http://www.boost.org/LICENSE_1_0.txt)
19//
20
21#include <boost/bind.hpp>
22#include <boost/ref.hpp>
23
24#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
25#pragma warning(push, 3)
26#endif
27
28#include <iostream>
29
30#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
31#pragma warning(pop)
32#endif
33
34#include <boost/detail/lightweight_test.hpp>
35
36//
37
38long global_result;
39
40long f_0()
41{
42 return global_result = 17041L;
43}
44
45long f_1(long a)
46{
47 return global_result = a;
48}
49
50long f_2(long a, long b)
51{
52 return global_result = a + 10 * b;
53}
54
55long f_3(long a, long b, long c)
56{
57 return global_result = a + 10 * b + 100 * c;
58}
59
60long f_4(long a, long b, long c, long d)
61{
62 return global_result = a + 10 * b + 100 * c + 1000 * d;
63}
64
65long f_5(long a, long b, long c, long d, long e)
66{
67 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e;
68}
69
70long f_6(long a, long b, long c, long d, long e, long f)
71{
72 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f;
73}
74
75long f_7(long a, long b, long c, long d, long e, long f, long g)
76{
77 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g;
78}
79
80long f_8(long a, long b, long c, long d, long e, long f, long g, long h)
81{
82 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h;
83}
84
85long f_9(long a, long b, long c, long d, long e, long f, long g, long h, long i)
86{
87 return global_result = a + 10 * b + 100 * c + 1000 * d + 10000 * e + 100000 * f + 1000000 * g + 10000000 * h + 100000000 * i;
88}
89
90void function_test()
91{
92 using namespace boost;
93
94 int const i = 1;
95
96 BOOST_TEST( (bind<void>(f_0)(i), (global_result == 17041L)) );
97 BOOST_TEST( (bind<void>(f_1, _1)(i), (global_result == 1L)) );
98 BOOST_TEST( (bind<void>(f_2, _1, 2)(i), (global_result == 21L)) );
99 BOOST_TEST( (bind<void>(f_3, _1, 2, 3)(i), (global_result == 321L)) );
100 BOOST_TEST( (bind<void>(f_4, _1, 2, 3, 4)(i), (global_result == 4321L)) );
101 BOOST_TEST( (bind<void>(f_5, _1, 2, 3, 4, 5)(i), (global_result == 54321L)) );
102 BOOST_TEST( (bind<void>(f_6, _1, 2, 3, 4, 5, 6)(i), (global_result == 654321L)) );
103 BOOST_TEST( (bind<void>(f_7, _1, 2, 3, 4, 5, 6, 7)(i), (global_result == 7654321L)) );
104 BOOST_TEST( (bind<void>(f_8, _1, 2, 3, 4, 5, 6, 7, 8)(i), (global_result == 87654321L)) );
105 BOOST_TEST( (bind<void>(f_9, _1, 2, 3, 4, 5, 6, 7, 8, 9)(i), (global_result == 987654321L)) );
106}
107
108//
109
110struct Y
111{
112 short operator()(short & r) const { return global_result = ++r; }
113 int operator()(int a, int b) const { return global_result = a + 10 * b; }
114 long operator() (long a, long b, long c) const { return global_result = a + 10 * b + 100 * c; }
115 void operator() (long a, long b, long c, long d) const { global_result = a + 10 * b + 100 * c + 1000 * d; }
116};
117
118void function_object_test()
119{
120 using namespace boost;
121
122 short i(6);
123
124 int const k = 3;
125
126 BOOST_TEST( (bind<void>(Y(), ref(i))(), (global_result == 7)) );
127 BOOST_TEST( (bind<void>(Y(), ref(i))(), (global_result == 8)) );
128 BOOST_TEST( (bind<void>(Y(), i, _1)(k), (global_result == 38)) );
129 BOOST_TEST( (bind<void>(Y(), i, _1, 9)(k), (global_result == 938)) );
130 BOOST_TEST( (bind<void>(Y(), i, _1, 9, 4)(k), (global_result == 4938)) );
131}
132
133int main()
134{
135 function_test();
136 function_object_test();
137
138 return boost::report_errors();
139}