add_inline_seq.cpp 763 B

12345678910111213141516171819202122232425262728
  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/detail/lightweight_test.hpp>
  8. #include <vector>
  9. #include <algorithm>
  10. int main(void) {
  11. int sum = 0, factor = 10;
  12. void BOOST_LOCAL_FUNCTION( (const bind factor) (bind& sum) (int num) ) {
  13. sum += factor * num;
  14. } BOOST_LOCAL_FUNCTION_NAME(inline add)
  15. std::vector<int> v(100);
  16. std::fill(v.begin(), v.end(), 1);
  17. for(size_t i = 0; i < v.size(); ++i) add(v[i]);
  18. BOOST_TEST(sum == 1000);
  19. return boost::report_errors();
  20. }