noncopyable_local_function.cpp 820 B

1234567891011121314151617181920212223242526272829303132
  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/noncopyable.hpp>
  8. #include <boost/typeof/typeof.hpp>
  9. #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
  10. #include <cassert>
  11. //[noncopyable_local_function
  12. struct n: boost::noncopyable {
  13. int i;
  14. n(int _i): i(_i) {}
  15. };
  16. BOOST_TYPEOF_REGISTER_TYPE(n) // Register for `bind& x` below.
  17. int main(void) {
  18. n x(-1);
  19. void BOOST_LOCAL_FUNCTION(const bind& x) { // OK: No copy
  20. assert(x.i == -1); // and constant.
  21. } BOOST_LOCAL_FUNCTION_NAME(f)
  22. f();
  23. return 0;
  24. }
  25. //]