noncopyable.qbk 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. [/
  2. Copyright 1999-2003 Beman Dawes
  3. Copyright 2014 Peter Dimov
  4. Distributed under the Boost Software License, Version 1.0.
  5. See accompanying file LICENSE_1_0.txt
  6. or copy at http://boost.org/LICENSE_1_0.txt
  7. ]
  8. [section:noncopyable noncopyable]
  9. [simplesect Authors]
  10. * Dave Abrahams
  11. [endsimplesect]
  12. [section Header <boost/core/noncopyable.hpp>]
  13. The header `<boost/core/noncopyable.hpp>` defines the class
  14. `boost::noncopyable`. It is intended to be used as a private
  15. base class. `boost::noncopyable` has private (under C++03) or
  16. deleted (under C++11) copy constructor and a copy assignment
  17. operator and can't be copied or assigned; a class that derives
  18. from it inherits these properties.
  19. `boost::noncopyable` was originally contributed by Dave
  20. Abrahams.
  21. [section Synopsis]
  22. ``
  23. namespace boost
  24. {
  25. class noncopyable;
  26. }
  27. ``
  28. [endsect]
  29. [section Example]
  30. ``
  31. #include <boost/core/noncopyable.hpp>
  32. class X: private boost::noncopyable
  33. {
  34. };
  35. ``
  36. [endsect]
  37. [section Rationale]
  38. Class noncopyable has protected constructor and destructor members to emphasize
  39. that it is to be used only as a base class. Dave Abrahams notes concern about
  40. the effect on compiler optimization of adding (even trivial inline) destructor
  41. declarations. He says:
  42. ["Probably this concern is misplaced, because `noncopyable` will be used mostly
  43. for classes which own resources and thus have non-trivial destruction semantics.]
  44. With C++2011, using an optimized and trivial constructor and similar destructor
  45. can be enforced by declaring both and marking them `default`. This is done in
  46. the current implementation.
  47. [endsect]
  48. [endsect]
  49. [endsect]