1 | // |
2 | // bind_over_test.cpp - overloaded 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 | using namespace boost::placeholders; |
15 | |
16 | // |
17 | |
18 | int f() |
19 | { |
20 | return 17041; |
21 | } |
22 | |
23 | int f( int x1 ) |
24 | { |
25 | return x1; |
26 | } |
27 | |
28 | int f( int x1, int x2 ) |
29 | { |
30 | return x1+x2; |
31 | } |
32 | |
33 | int f( int x1, int x2, int x3 ) |
34 | { |
35 | return x1+x2+x3; |
36 | } |
37 | |
38 | int f( int x1, int x2, int x3, int x4 ) |
39 | { |
40 | return x1+x2+x3+x4; |
41 | } |
42 | |
43 | int f( int x1, int x2, int x3, int x4, int x5 ) |
44 | { |
45 | return x1+x2+x3+x4+x5; |
46 | } |
47 | |
48 | int f( int x1, int x2, int x3, int x4, int x5, int x6 ) |
49 | { |
50 | return x1+x2+x3+x4+x5+x6; |
51 | } |
52 | |
53 | int f( int x1, int x2, int x3, int x4, int x5, int x6, int x7 ) |
54 | { |
55 | return x1+x2+x3+x4+x5+x6+x7; |
56 | } |
57 | |
58 | int f( int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8 ) |
59 | { |
60 | return x1+x2+x3+x4+x5+x6+x7+x8; |
61 | } |
62 | |
63 | int f( int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9 ) |
64 | { |
65 | return x1+x2+x3+x4+x5+x6+x7+x8+x9; |
66 | } |
67 | |
68 | void overloaded_function_test() |
69 | { |
70 | BOOST_TEST_EQ( boost::bind( f )(), 17041 ); |
71 | BOOST_TEST_EQ( boost::bind( f, 1 )(), 1 ); |
72 | BOOST_TEST_EQ( boost::bind( f, 1, 2 )(), 1+2 ); |
73 | BOOST_TEST_EQ( boost::bind( f, 1, 2, 3 )(), 1+2+3 ); |
74 | BOOST_TEST_EQ( boost::bind( f, 1, 2, 3, 4 )(), 1+2+3+4 ); |
75 | BOOST_TEST_EQ( boost::bind( f, 1, 2, 3, 4, 5 )(), 1+2+3+4+5 ); |
76 | BOOST_TEST_EQ( boost::bind( f, 1, 2, 3, 4, 5, 6 )(), 1+2+3+4+5+6 ); |
77 | BOOST_TEST_EQ( boost::bind( f, 1, 2, 3, 4, 5, 6, 7 )(), 1+2+3+4+5+6+7 ); |
78 | BOOST_TEST_EQ( boost::bind( f, 1, 2, 3, 4, 5, 6, 7, 8 )(), 1+2+3+4+5+6+7+8 ); |
79 | BOOST_TEST_EQ( boost::bind( f, 1, 2, 3, 4, 5, 6, 7, 8, 9 )(), 1+2+3+4+5+6+7+8+9 ); |
80 | } |
81 | |
82 | int main() |
83 | { |
84 | overloaded_function_test(); |
85 | return boost::report_errors(); |
86 | } |
87 | |