gcc_cxx11_lambda.cpp 784 B

1234567891011121314151617181920212223242526272829303132333435
  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/config.hpp>
  7. #ifdef BOOST_NO_CXX11_LAMBDAS
  8. # error "lambda functions required"
  9. #else
  10. #include <boost/detail/lightweight_test.hpp>
  11. #include <algorithm>
  12. int main(void) {
  13. //[gcc_cxx11_lambda
  14. int val = 2;
  15. int nums[] = {1, 2, 3};
  16. int* end = nums + 3;
  17. int* iter = std::find_if(nums, end,
  18. [val](int num) -> bool {
  19. return num == val;
  20. }
  21. );
  22. //]
  23. BOOST_TEST(iter != end);
  24. BOOST_TEST(*iter == val);
  25. return boost::report_errors();
  26. }
  27. #endif // LAMBDAS