• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/local_function.hpp>
9 #include <boost/typeof/typeof.hpp>
10 #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
11 #include <iostream>
12 #include <cassert>
13 
14 //[expensive_copy_local_function
15 struct n {
16     int i;
nn17     n(int _i): i(_i) {}
nn18     n(n const& x): i(x.i) { // Some time consuming copy operation.
19         for (unsigned i = 0; i < 10000; ++i) std::cout << '.';
20     }
21 };
BOOST_TYPEOF_REGISTER_TYPE(n)22 BOOST_TYPEOF_REGISTER_TYPE(n) // Register for `bind& x` below.
23 
24 int main(void) {
25     n x(-1);
26 
27     void BOOST_LOCAL_FUNCTION(const bind& x) {  // OK: No copy expensive
28         assert(x.i == -1);                      // copy but constant.
29     } BOOST_LOCAL_FUNCTION_NAME(f)
30     f();
31 
32     return 0;
33 }
34 //]
35 
36