noncopyable.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Boost noncopyable.hpp header file --------------------------------------//
  2. // (C) Copyright Beman Dawes 1999-2003. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/utility for documentation.
  6. #ifndef BOOST_CORE_NONCOPYABLE_HPP
  7. #define BOOST_CORE_NONCOPYABLE_HPP
  8. #include <boost/config.hpp>
  9. namespace boost {
  10. // Private copy constructor and copy assignment ensure classes derived from
  11. // class noncopyable cannot be copied.
  12. // Contributed by Dave Abrahams
  13. namespace noncopyable_ // protection from unintended ADL
  14. {
  15. #ifndef BOOST_NONCOPYABLE_BASE_TOKEN_DEFINED
  16. #define BOOST_NONCOPYABLE_BASE_TOKEN_DEFINED
  17. // noncopyable derives from base_token to enable Type Traits to detect
  18. // whether a type derives from noncopyable without needing the definition
  19. // of noncopyable itself.
  20. //
  21. // The definition of base_token is macro-guarded so that Type Trais can
  22. // define it locally without including this header, to avoid a dependency
  23. // on Core.
  24. struct base_token {};
  25. #endif // #ifndef BOOST_NONCOPYABLE_BASE_TOKEN_DEFINED
  26. class noncopyable: base_token
  27. {
  28. protected:
  29. #if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
  30. BOOST_CONSTEXPR noncopyable() = default;
  31. ~noncopyable() = default;
  32. #else
  33. noncopyable() {}
  34. ~noncopyable() {}
  35. #endif
  36. #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
  37. noncopyable( const noncopyable& ) = delete;
  38. noncopyable& operator=( const noncopyable& ) = delete;
  39. #else
  40. private: // emphasize the following members are private
  41. noncopyable( const noncopyable& );
  42. noncopyable& operator=( const noncopyable& );
  43. #endif
  44. };
  45. }
  46. typedef noncopyable_::noncopyable noncopyable;
  47. } // namespace boost
  48. #endif // BOOST_CORE_NONCOPYABLE_HPP