boost_has_nrvo.ipp 844 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // (C) Copyright Terje Slettebo 2001.
  2. // (C) Copyright John Maddock 2001.
  3. // Use, modification and distribution are subject to the
  4. // Boost Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org/libs/config for most recent version.
  7. // MACRO: BOOST_HAS_NRVO
  8. // TITLE: Named return value optimisation.
  9. // DESCRIPTION: Named return value optimisation.
  10. namespace boost_has_nrvo
  11. {
  12. class test_class
  13. {
  14. public:
  15. test_class() {}
  16. test_class(const test_class&)
  17. {
  18. ++copy_count;
  19. }
  20. static int copy_count;
  21. };
  22. int test_class::copy_count;
  23. test_class f()
  24. {
  25. test_class nrv;
  26. return nrv;
  27. }
  28. int test()
  29. {
  30. test_class::copy_count=0;
  31. f();
  32. return test_class::copy_count;
  33. }
  34. } // namespace boost_has_nrvo