Imported Upstream version 1.51.0
[platform/upstream/boost.git] / libs / local_function / test / add.cpp
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_VARIADIC_MACROS
10 #   error "variadic macros required"
11 #else
12
13 #include <boost/local_function.hpp>
14 #include <boost/detail/lightweight_test.hpp>
15 #include <algorithm>
16
17 //[add
18 int main(void) {                            // Some local scope.
19     int sum = 0, factor = 10;               // Variables in scope to bind.
20     
21     void BOOST_LOCAL_FUNCTION(const bind factor, bind& sum, int num) {
22         sum += factor * num;
23     } BOOST_LOCAL_FUNCTION_NAME(add)
24     
25     add(1);                                 // Call the local function.
26     int nums[] = {2, 3};
27     std::for_each(nums, nums + 2, add);     // Pass it to an algorithm.
28
29     BOOST_TEST(sum == 60);                  // Assert final summation value.
30     return boost::report_errors();
31 }
32 //]
33
34 #endif // VARIADIC_MACROS
35