• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/local_function.hpp>
9 #include <boost/function.hpp>
10 #include <boost/detail/lightweight_test.hpp>
11 
intermediate(boost::function<void (int,int)> store_func,int size)12 void intermediate(boost::function<void (int, int)> store_func, int size) {
13     store_func(size - 1, -1);
14 }
15 
hack(int * array,int size)16 void hack(int* array, int size) {
17     void BOOST_LOCAL_FUNCTION(bind array, int index, int value) {
18         array[index] = value;
19     } BOOST_LOCAL_FUNCTION_NAME(store)
20 
21     intermediate(store, size);
22 }
23 
main(void)24 int main(void) {
25     int nums[] = {1, 2, 3};
26     hack(nums, 3);
27 
28     BOOST_TEST(nums[0] == 1);
29     BOOST_TEST(nums[1] == 2);
30     BOOST_TEST(nums[2] == -1);
31     return boost::report_errors();
32 }
33 
34