]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/lambda/test/bind_tests_simple_f_refs.cpp
1 // bind_tests_simple.cpp -- The Boost Lambda Library ------------------
3 // Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
4 // Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // For more information, see www.boost.org
12 // -----------------------------------------------------------------------
15 #include <boost/core/lightweight_test.hpp>
16 #define BOOST_CHECK BOOST_TEST
18 #include "boost/lambda/bind.hpp"
22 using namespace boost::lambda
;
25 int sum_of_args_0() { return 0; }
26 int sum_of_args_1(int a
) { return a
; }
27 int sum_of_args_2(int a
, int b
) { return a
+b
; }
28 int sum_of_args_3(int a
, int b
, int c
) { return a
+b
+c
; }
29 int sum_of_args_4(int a
, int b
, int c
, int d
) { return a
+b
+c
+d
; }
30 int sum_of_args_5(int a
, int b
, int c
, int d
, int e
) { return a
+b
+c
+d
+e
; }
31 int sum_of_args_6(int a
, int b
, int c
, int d
, int e
, int f
) { return a
+b
+c
+d
+e
+f
; }
32 int sum_of_args_7(int a
, int b
, int c
, int d
, int e
, int f
, int g
) { return a
+b
+c
+d
+e
+f
+g
; }
33 int sum_of_args_8(int a
, int b
, int c
, int d
, int e
, int f
, int g
, int h
) { return a
+b
+c
+d
+e
+f
+g
+h
; }
34 int sum_of_args_9(int a
, int b
, int c
, int d
, int e
, int f
, int g
, int h
, int i
) { return a
+b
+c
+d
+e
+f
+g
+h
+i
; }
37 // ----------------------------
43 int add(const int& j
) { return i
+ j
; }
46 void test_member_functions()
52 BOOST_CHECK(bind(&A::add
, ref(a
), _1
)(i
) == 11);
53 BOOST_CHECK(bind(&A::add
, &a
, _1
)(i
) == 11);
54 BOOST_CHECK(bind(&A::add
, _1
, 1)(a
) == 11);
55 BOOST_CHECK(bind(&A::add
, _1
, 1)(make_const(&a
)) == 11);
57 // This should fail, as lambda functors store arguments as const
58 // bind(&A::add, a, _1);
63 int i
= 1; int j
= 2; int k
= 3;
67 // bind all parameters
68 BOOST_CHECK(bind(sum_of_args_0
)()==0);
69 BOOST_CHECK(bind(sum_of_args_1
, 1)()==1);
70 BOOST_CHECK(bind(sum_of_args_2
, 1, 2)()==3);
71 BOOST_CHECK(bind(sum_of_args_3
, 1, 2, 3)()==6);
72 BOOST_CHECK(bind(sum_of_args_4
, 1, 2, 3, 4)()==10);
73 BOOST_CHECK(bind(sum_of_args_5
, 1, 2, 3, 4, 5)()==15);
74 BOOST_CHECK(bind(sum_of_args_6
, 1, 2, 3, 4, 5, 6)()==21);
75 BOOST_CHECK(bind(sum_of_args_7
, 1, 2, 3, 4, 5, 6, 7)()==28);
76 BOOST_CHECK(bind(sum_of_args_8
, 1, 2, 3, 4, 5, 6, 7, 8)()==36);
77 BOOST_CHECK(bind(sum_of_args_9
, 1, 2, 3, 4, 5, 6, 7, 8, 9)()==45);
79 // first parameter open
80 BOOST_CHECK(bind(sum_of_args_0
)()==0);
81 BOOST_CHECK(bind(sum_of_args_1
, _1
)(i
)==1);
82 BOOST_CHECK(bind(sum_of_args_2
, _1
, 2)(i
)==3);
83 BOOST_CHECK(bind(sum_of_args_3
, _1
, 2, 3)(i
)==6);
84 BOOST_CHECK(bind(sum_of_args_4
, _1
, 2, 3, 4)(i
)==10);
85 BOOST_CHECK(bind(sum_of_args_5
, _1
, 2, 3, 4, 5)(i
)==15);
86 BOOST_CHECK(bind(sum_of_args_6
, _1
, 2, 3, 4, 5, 6)(i
)==21);
87 BOOST_CHECK(bind(sum_of_args_7
, _1
, 2, 3, 4, 5, 6, 7)(i
)==28);
88 BOOST_CHECK(bind(sum_of_args_8
, _1
, 2, 3, 4, 5, 6, 7, 8)(i
)==36);
89 BOOST_CHECK(bind(sum_of_args_9
, _1
, 2, 3, 4, 5, 6, 7, 8, 9)(i
)==45);
92 BOOST_CHECK(bind(sum_of_args_0
)()==0);
93 BOOST_CHECK(bind(sum_of_args_1
, _1
)(i
)==1);
94 BOOST_CHECK(bind(sum_of_args_2
, _1
, _2
)(i
, j
)==3);
95 BOOST_CHECK(bind(sum_of_args_3
, _1
, _2
, 3)(i
, j
)==6);
96 BOOST_CHECK(bind(sum_of_args_4
, _1
, _2
, 3, 4)(i
, j
)==10);
97 BOOST_CHECK(bind(sum_of_args_5
, _1
, _2
, 3, 4, 5)(i
, j
)==15);
98 BOOST_CHECK(bind(sum_of_args_6
, _1
, _2
, 3, 4, 5, 6)(i
, j
)==21);
99 BOOST_CHECK(bind(sum_of_args_7
, _1
, _2
, 3, 4, 5, 6, 7)(i
, j
)==28);
100 BOOST_CHECK(bind(sum_of_args_8
, _1
, _2
, 3, 4, 5, 6, 7, 8)(i
, j
)==36);
101 BOOST_CHECK(bind(sum_of_args_9
, _1
, _2
, 3, 4, 5, 6, 7, 8, 9)(i
, j
)==45);
103 // three open arguments
104 BOOST_CHECK(bind(sum_of_args_0
)()==0);
105 BOOST_CHECK(bind(sum_of_args_1
, _1
)(i
)==1);
106 BOOST_CHECK(bind(sum_of_args_2
, _1
, _2
)(i
, j
)==3);
107 BOOST_CHECK(bind(sum_of_args_3
, _1
, _2
, _3
)(i
, j
, k
)==6);
108 BOOST_CHECK(bind(sum_of_args_4
, _1
, _2
, _3
, 4)(i
, j
, k
)==10);
109 BOOST_CHECK(bind(sum_of_args_5
, _1
, _2
, _3
, 4, 5)(i
, j
, k
)==15);
110 BOOST_CHECK(bind(sum_of_args_6
, _1
, _2
, _3
, 4, 5, 6)(i
, j
, k
)==21);
111 BOOST_CHECK(bind(sum_of_args_7
, _1
, _2
, _3
, 4, 5, 6, 7)(i
, j
, k
)==28);
112 BOOST_CHECK(bind(sum_of_args_8
, _1
, _2
, _3
, 4, 5, 6, 7, 8)(i
, j
, k
)==36);
113 BOOST_CHECK(bind(sum_of_args_9
, _1
, _2
, _3
, 4, 5, 6, 7, 8, 9)(i
, j
, k
)==45);
115 // function compositions with bind
116 BOOST_CHECK(bind(sum_of_args_3
, bind(sum_of_args_2
, _1
, 2), 2, 3)(i
)==8);
119 bind(sum_of_args_0
), // 0
120 bind(sum_of_args_1
, _1
), // 1
121 bind(sum_of_args_2
, _1
, _2
), // 3
122 bind(sum_of_args_3
, _1
, _2
, _3
), // 6
123 bind(sum_of_args_4
, _1
, _2
, _3
, 4), // 10
124 bind(sum_of_args_5
, _1
, _2
, _3
, 4, 5), // 15
125 bind(sum_of_args_6
, _1
, _2
, _3
, 4, 5, 6), // 21
126 bind(sum_of_args_7
, _1
, _2
, _3
, 4, 5, 6, 7), // 28
127 bind(sum_of_args_8
, _1
, _2
, _3
, 4, 5, 6, 7, 8) // 36
132 bind(sum_of_args_1
, // 12
133 bind(sum_of_args_4
, // 12
134 bind(sum_of_args_2
, // 3
135 bind(sum_of_args_1
, // 1
136 bind(sum_of_args_1
, _1
) // 1
143 BOOST_CHECK(result
== 12);
145 test_member_functions();
148 return boost::report_errors();