ゴミ箱
empty_base_optimization.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9 
10 #ifndef BOOST_BEAST_DETAIL_EMPTY_BASE_OPTIMIZATION_HPP
11 #define BOOST_BEAST_DETAIL_EMPTY_BASE_OPTIMIZATION_HPP
12 
13 #include <boost/type_traits/is_final.hpp>
14 #include <type_traits>
15 #include <utility>
16 
17 namespace boost {
18 namespace beast {
19 namespace detail {
20 
21 template<class T>
23  : std::integral_constant<bool,
24  std::is_empty<T>::value &&
25  ! boost::is_final<T>::value>
26 {
27 };
28 
29 template<
30  class T,
31  int UniqueID = 0,
32  bool ShouldDeriveFrom =
34 >
35 class empty_base_optimization : private T
36 {
37 public:
38  empty_base_optimization() = default;
39 
41  : T (t)
42  {}
43 
45  : T (std::move (t))
46  {}
47 
48  T& member() noexcept
49  {
50  return *this;
51  }
52 
53  T const& member() const noexcept
54  {
55  return *this;
56  }
57 };
58 
59 //------------------------------------------------------------------------------
60 
61 template<
62  class T,
63  int UniqueID
64 >
65 class empty_base_optimization <T, UniqueID, false>
66 {
67 public:
68  empty_base_optimization() = default;
69 
71  : m_t (t)
72  {}
73 
75  : m_t (std::move (t))
76  {}
77 
78  T& member() noexcept
79  {
80  return m_t;
81  }
82 
83  T const& member() const noexcept
84  {
85  return m_t;
86  }
87 
88 private:
89  T m_t;
90 };
91 
92 } // detail
93 } // beast
94 } // boost
95 
96 #endif
T const & member() const noexcept
Definition: empty_base_optimization.hpp:53
Definition: async_result.hpp:20
STL namespace.
empty_base_optimization(T &&t)
Definition: empty_base_optimization.hpp:44
Definition: empty_base_optimization.hpp:22
empty_base_optimization(T const &t)
Definition: empty_base_optimization.hpp:40
empty_base_optimization(T &&t)
Definition: empty_base_optimization.hpp:74
T & member() noexcept
Definition: empty_base_optimization.hpp:78
empty_base_optimization(T const &t)
Definition: empty_base_optimization.hpp:70
Definition: empty_base_optimization.hpp:35
T & member() noexcept
Definition: empty_base_optimization.hpp:48
T const & member() const noexcept
Definition: empty_base_optimization.hpp:83