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

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