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

source code of include/boost/core/noncopyable.hpp