gcc_store.cpp 877 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (C) 2009-2012 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0
  3. // (see accompanying file LICENSE_1_0.txt or a copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Home at http://www.boost.org/libs/local_function
  6. #include <boost/local_function.hpp>
  7. #include <boost/function.hpp>
  8. #include <boost/detail/lightweight_test.hpp>
  9. void intermediate(boost::function<void (int, int)> store_func, int size) {
  10. store_func(size - 1, -1);
  11. }
  12. void hack(int* array, int size) {
  13. void BOOST_LOCAL_FUNCTION(bind array, int index, int value) {
  14. array[index] = value;
  15. } BOOST_LOCAL_FUNCTION_NAME(store)
  16. intermediate(store, size);
  17. }
  18. int main(void) {
  19. int nums[] = {1, 2, 3};
  20. hack(nums, 3);
  21. BOOST_TEST(nums[0] == 1);
  22. BOOST_TEST(nums[1] == 2);
  23. BOOST_TEST(nums[2] == -1);
  24. return boost::report_errors();
  25. }