]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/local_function/test/add_this_seq.cpp
2 // Copyright (C) 2009-2012 Lorenzo Caminiti
3 // Distributed under the Boost Software License, Version 1.0
4 // (see accompanying file LICENSE_1_0.txt or a copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 // Home at http://www.boost.org/libs/local_function
8 #include <boost/local_function.hpp>
9 #include <boost/typeof/typeof.hpp>
10 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
11 #include <boost/detail/lightweight_test.hpp>
16 BOOST_TYPEOF_REGISTER_TYPE(adder
) // Register before `bind this_` below.
21 int sum(const std::vector
<int>& nums
, const int factor
= 10) {
23 void BOOST_LOCAL_FUNCTION( (const bind factor
) (bind this_
)
25 this_
->sum_
+= factor
* num
;
26 } BOOST_LOCAL_FUNCTION_NAME(add
)
28 std::for_each(nums
.begin(), nums
.end(), add
);
37 std::vector
<int> v(3);
38 v
[0] = 1; v
[1] = 2; v
[2] = 3;
40 BOOST_TEST(adder().sum(v
) == 60);
41 return boost::report_errors();