1//
2// bind_over_mf_test.cpp - overloaded member functions
3//
4// Copyright 2017, 2024 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/core/lightweight_test.hpp>
13
14//
15
16struct X
17{
18 int f() { return 17041; }
19 int f( int x1 ) { return x1; }
20 int f( int x1, int x2 ) { return x1+x2; }
21 int f( int x1, int x2, int x3 ) { return x1+x2+x3; }
22 int f( int x1, int x2, int x3, int x4 ) { return x1+x2+x3+x4; }
23 int f( int x1, int x2, int x3, int x4, int x5 ) { return x1+x2+x3+x4+x5; }
24 int f( int x1, int x2, int x3, int x4, int x5, int x6 ) { return x1+x2+x3+x4+x5+x6; }
25 int f( int x1, int x2, int x3, int x4, int x5, int x6, int x7 ) { return x1+x2+x3+x4+x5+x6+x7; }
26 int f( int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8 ) { return x1+x2+x3+x4+x5+x6+x7+x8; }
27 int f( int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9 ) { return x1+x2+x3+x4+x5+x6+x7+x8+x9; }
28
29 int g() const { return 17041; }
30 int g( int x1 ) const { return x1; }
31 int g( int x1, int x2 ) const { return x1+x2; }
32 int g( int x1, int x2, int x3 ) const { return x1+x2+x3; }
33 int g( int x1, int x2, int x3, int x4 ) const { return x1+x2+x3+x4; }
34 int g( int x1, int x2, int x3, int x4, int x5 ) const { return x1+x2+x3+x4+x5; }
35 int g( int x1, int x2, int x3, int x4, int x5, int x6 ) const { return x1+x2+x3+x4+x5+x6; }
36 int g( int x1, int x2, int x3, int x4, int x5, int x6, int x7 ) const { return x1+x2+x3+x4+x5+x6+x7; }
37 int g( int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8 ) const { return x1+x2+x3+x4+x5+x6+x7+x8; }
38 int g( int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9 ) const { return x1+x2+x3+x4+x5+x6+x7+x8+x9; }
39};
40
41void overloaded_member_function_test()
42{
43 X x;
44
45 BOOST_TEST_EQ( boost::bind( &X::f, &x )(), 17041 );
46 BOOST_TEST_EQ( boost::bind( &X::f, &x, 1 )(), 1 );
47 BOOST_TEST_EQ( boost::bind( &X::f, &x, 1, 2 )(), 1+2 );
48 BOOST_TEST_EQ( boost::bind( &X::f, &x, 1, 2, 3 )(), 1+2+3 );
49 BOOST_TEST_EQ( boost::bind( &X::f, &x, 1, 2, 3, 4 )(), 1+2+3+4 );
50 BOOST_TEST_EQ( boost::bind( &X::f, &x, 1, 2, 3, 4, 5 )(), 1+2+3+4+5 );
51 BOOST_TEST_EQ( boost::bind( &X::f, &x, 1, 2, 3, 4, 5, 6 )(), 1+2+3+4+5+6 );
52 BOOST_TEST_EQ( boost::bind( &X::f, &x, 1, 2, 3, 4, 5, 6, 7 )(), 1+2+3+4+5+6+7 );
53 BOOST_TEST_EQ( boost::bind( &X::f, &x, 1, 2, 3, 4, 5, 6, 7, 8 )(), 1+2+3+4+5+6+7+8 );
54
55 BOOST_TEST_EQ( boost::bind<int>( &X::f, &x )(), 17041 );
56 BOOST_TEST_EQ( boost::bind<int>( &X::f, &x, 1 )(), 1 );
57 BOOST_TEST_EQ( boost::bind<int>( &X::f, &x, 1, 2 )(), 1+2 );
58 BOOST_TEST_EQ( boost::bind<int>( &X::f, &x, 1, 2, 3 )(), 1+2+3 );
59 BOOST_TEST_EQ( boost::bind<int>( &X::f, &x, 1, 2, 3, 4 )(), 1+2+3+4 );
60 BOOST_TEST_EQ( boost::bind<int>( &X::f, &x, 1, 2, 3, 4, 5 )(), 1+2+3+4+5 );
61 BOOST_TEST_EQ( boost::bind<int>( &X::f, &x, 1, 2, 3, 4, 5, 6 )(), 1+2+3+4+5+6 );
62 BOOST_TEST_EQ( boost::bind<int>( &X::f, &x, 1, 2, 3, 4, 5, 6, 7 )(), 1+2+3+4+5+6+7 );
63 BOOST_TEST_EQ( boost::bind<int>( &X::f, &x, 1, 2, 3, 4, 5, 6, 7, 8 )(), 1+2+3+4+5+6+7+8 );
64
65 BOOST_TEST_EQ( boost::bind<long>( &X::f, &x )(), 17041 );
66 BOOST_TEST_EQ( boost::bind<long>( &X::f, &x, 1 )(), 1 );
67 BOOST_TEST_EQ( boost::bind<long>( &X::f, &x, 1, 2 )(), 1+2 );
68 BOOST_TEST_EQ( boost::bind<long>( &X::f, &x, 1, 2, 3 )(), 1+2+3 );
69 BOOST_TEST_EQ( boost::bind<long>( &X::f, &x, 1, 2, 3, 4 )(), 1+2+3+4 );
70 BOOST_TEST_EQ( boost::bind<long>( &X::f, &x, 1, 2, 3, 4, 5 )(), 1+2+3+4+5 );
71 BOOST_TEST_EQ( boost::bind<long>( &X::f, &x, 1, 2, 3, 4, 5, 6 )(), 1+2+3+4+5+6 );
72 BOOST_TEST_EQ( boost::bind<long>( &X::f, &x, 1, 2, 3, 4, 5, 6, 7 )(), 1+2+3+4+5+6+7 );
73 BOOST_TEST_EQ( boost::bind<long>( &X::f, &x, 1, 2, 3, 4, 5, 6, 7, 8 )(), 1+2+3+4+5+6+7+8 );
74
75 X const* pcx = &x;
76
77 BOOST_TEST_EQ( boost::bind( &X::g, pcx )(), 17041 );
78 BOOST_TEST_EQ( boost::bind( &X::g, pcx, 1 )(), 1 );
79 BOOST_TEST_EQ( boost::bind( &X::g, pcx, 1, 2 )(), 1+2 );
80 BOOST_TEST_EQ( boost::bind( &X::g, pcx, 1, 2, 3 )(), 1+2+3 );
81 BOOST_TEST_EQ( boost::bind( &X::g, pcx, 1, 2, 3, 4 )(), 1+2+3+4 );
82 BOOST_TEST_EQ( boost::bind( &X::g, pcx, 1, 2, 3, 4, 5 )(), 1+2+3+4+5 );
83 BOOST_TEST_EQ( boost::bind( &X::g, pcx, 1, 2, 3, 4, 5, 6 )(), 1+2+3+4+5+6 );
84 BOOST_TEST_EQ( boost::bind( &X::g, pcx, 1, 2, 3, 4, 5, 6, 7 )(), 1+2+3+4+5+6+7 );
85 BOOST_TEST_EQ( boost::bind( &X::g, pcx, 1, 2, 3, 4, 5, 6, 7, 8 )(), 1+2+3+4+5+6+7+8 );
86
87 BOOST_TEST_EQ( boost::bind<int>( &X::g, pcx )(), 17041 );
88 BOOST_TEST_EQ( boost::bind<int>( &X::g, pcx, 1 )(), 1 );
89 BOOST_TEST_EQ( boost::bind<int>( &X::g, pcx, 1, 2 )(), 1+2 );
90 BOOST_TEST_EQ( boost::bind<int>( &X::g, pcx, 1, 2, 3 )(), 1+2+3 );
91 BOOST_TEST_EQ( boost::bind<int>( &X::g, pcx, 1, 2, 3, 4 )(), 1+2+3+4 );
92 BOOST_TEST_EQ( boost::bind<int>( &X::g, pcx, 1, 2, 3, 4, 5 )(), 1+2+3+4+5 );
93 BOOST_TEST_EQ( boost::bind<int>( &X::g, pcx, 1, 2, 3, 4, 5, 6 )(), 1+2+3+4+5+6 );
94 BOOST_TEST_EQ( boost::bind<int>( &X::g, pcx, 1, 2, 3, 4, 5, 6, 7 )(), 1+2+3+4+5+6+7 );
95 BOOST_TEST_EQ( boost::bind<int>( &X::g, pcx, 1, 2, 3, 4, 5, 6, 7, 8 )(), 1+2+3+4+5+6+7+8 );
96
97 BOOST_TEST_EQ( boost::bind<long>( &X::g, pcx )(), 17041 );
98 BOOST_TEST_EQ( boost::bind<long>( &X::g, pcx, 1 )(), 1 );
99 BOOST_TEST_EQ( boost::bind<long>( &X::g, pcx, 1, 2 )(), 1+2 );
100 BOOST_TEST_EQ( boost::bind<long>( &X::g, pcx, 1, 2, 3 )(), 1+2+3 );
101 BOOST_TEST_EQ( boost::bind<long>( &X::g, pcx, 1, 2, 3, 4 )(), 1+2+3+4 );
102 BOOST_TEST_EQ( boost::bind<long>( &X::g, pcx, 1, 2, 3, 4, 5 )(), 1+2+3+4+5 );
103 BOOST_TEST_EQ( boost::bind<long>( &X::g, pcx, 1, 2, 3, 4, 5, 6 )(), 1+2+3+4+5+6 );
104 BOOST_TEST_EQ( boost::bind<long>( &X::g, pcx, 1, 2, 3, 4, 5, 6, 7 )(), 1+2+3+4+5+6+7 );
105 BOOST_TEST_EQ( boost::bind<long>( &X::g, pcx, 1, 2, 3, 4, 5, 6, 7, 8 )(), 1+2+3+4+5+6+7+8 );
106}
107
108int main()
109{
110 overloaded_member_function_test();
111 return boost::report_errors();
112}
113

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