]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/local_function/test/return_this.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/config.hpp>
9 #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
10 # error "variadic macros required"
13 #include <boost/local_function.hpp>
14 #include <boost/function.hpp>
15 #include <boost/typeof/typeof.hpp>
16 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
17 #include <boost/detail/lightweight_test.hpp>
20 BOOST_TYPEOF_REGISTER_TYPE(number
) // Register before `bind this_` below.
23 number(int value
) : value_(value
) {}
25 boost::function
<int (void)> inc(void) {
26 int BOOST_LOCAL_FUNCTION(bind this_
) {
27 return ++this_
->value_
;
28 } BOOST_LOCAL_FUNCTION_NAME(i
)
37 number n1
= 0; // Object valid in scope where closure is used.
38 boost::function
<int (void)> inc1
= n1
.inc();
40 boost::function
<int (void)> inc2
= n2
.inc();
42 BOOST_TEST(inc1() == 1);
43 BOOST_TEST(inc1() == 2);
44 BOOST_TEST(inc2() == 1);
45 BOOST_TEST(inc1() == 3);
46 return boost::report_errors();
49 #endif // VARIADIC_MACROS