const_block_error_cxx11_lambda.cpp 777 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/config.hpp>
  7. #ifdef BOOST_NO_CXX11_LAMBDAS
  8. # error "requires lambda functions"
  9. #else
  10. #include <cassert>
  11. int main(void) {
  12. //[const_block_cxx11_lambda
  13. int x = 1, y = 2;
  14. const decltype(x)& const_x = x; // Constant so cannot be modified
  15. const decltype(y)& const_y = y; // and reference so no copy.
  16. [&const_x, &const_y]() { // Lambda functions (C++11 only).
  17. assert(const_x = const_y); // Unfortunately, `const_` names.
  18. }();
  19. //]
  20. return 0;
  21. }
  22. #endif // LAMBDAS