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/config.hpp> 9 #ifdef BOOST_NO_CXX11_LAMBDAS 10 # error "lambda functions required" 11 #else 12 13 #include <iostream> 14 #include <cassert> 15 16 //[expensive_copy_cxx11_lambda 17 struct n { 18 int i; nn19 n(int _i): i(_i) {} nn20 n(n const& x): i(x.i) { // Some time consuming copy operation. 21 for (unsigned i = 0; i < 10000; ++i) std::cout << '.'; 22 } 23 }; 24 25 main(void)26int main(void) { 27 n x(-1); 28 29 auto f = [x]() { // Problem: Expensive copy, but if bind 30 assert(x.i == -1); // by `&x` then `x` is not constant. 31 }; 32 f(); 33 34 return 0; 35 } 36 //] 37 38 #endif // NO_LAMBDAS 39 40