1 | |
---|---|
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 |
7 | |
8 | #include <boost/config.hpp> |
9 | #ifdef BOOST_NO_CXX11_VARIADIC_MACROS |
10 | # error "variadic macros required" |
11 | #else |
12 | |
13 | #include "addable.hpp" |
14 | #include <boost/local_function.hpp> |
15 | #include <boost/type_traits/remove_reference.hpp> |
16 | #include <boost/concept_check.hpp> |
17 | #include <boost/detail/lightweight_test.hpp> |
18 | #include <algorithm> |
19 | |
20 | int main(void) { |
21 | //[typeof |
22 | int sum = 0, factor = 10; |
23 | |
24 | void BOOST_LOCAL_FUNCTION(const bind factor, bind& sum, int num) { |
25 | // Type-of for concept checking. |
26 | BOOST_CONCEPT_ASSERT((Addable<boost::remove_reference< |
27 | BOOST_LOCAL_FUNCTION_TYPEOF(sum)>::type>)); |
28 | // Type-of for declarations. |
29 | boost::remove_reference<BOOST_LOCAL_FUNCTION_TYPEOF( |
30 | factor)>::type mult = factor * num; |
31 | sum += mult; |
32 | } BOOST_LOCAL_FUNCTION_NAME(add) |
33 | |
34 | add(6); |
35 | //] |
36 | BOOST_TEST(sum == 60); |
37 | return boost::report_errors(); |
38 | } |
39 | |
40 | #endif // VARIADIC_MACROS |
41 | |
42 |