]> git.proxmox.com Git - ceph.git/blame - ceph/src/Beast/include/beast/core/detail/empty_base_optimization.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / include / beast / core / detail / empty_base_optimization.hpp
CommitLineData
7c673cae
FG
1//
2// Copyright (c) 2013-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
8#ifndef BEAST_DETAIL_EMPTY_BASE_OPTIMIZATION_HPP
9#define BEAST_DETAIL_EMPTY_BASE_OPTIMIZATION_HPP
10
11#include <type_traits>
12#include <utility>
13
14namespace beast {
15namespace detail {
16
17template<class T>
18struct empty_base_optimization_decide
19 : std::integral_constant <bool,
20 std::is_empty <T>::value
21#ifdef __clang__
22 && !__is_final(T)
23#endif
24 >
25{
26};
27
28template<
29 class T,
30 int UniqueID = 0,
31 bool ShouldDeriveFrom =
32 empty_base_optimization_decide<T>::value
33>
34class empty_base_optimization : private T
35{
36public:
37 empty_base_optimization() = default;
38
39 empty_base_optimization(T const& t)
40 : T (t)
41 {}
42
43 empty_base_optimization(T&& t)
44 : T (std::move (t))
45 {}
46
47 T& member() noexcept
48 {
49 return *this;
50 }
51
52 T const& member() const noexcept
53 {
54 return *this;
55 }
56};
57
58//------------------------------------------------------------------------------
59
60template<
61 class T,
62 int UniqueID
63>
64class empty_base_optimization <T, UniqueID, false>
65{
66public:
67 empty_base_optimization() = default;
68
69 empty_base_optimization(T const& t)
70 : m_t (t)
71 {}
72
73 empty_base_optimization(T&& t)
74 : m_t (std::move (t))
75 {}
76
77 T& member() noexcept
78 {
79 return m_t;
80 }
81
82 T const& member() const noexcept
83 {
84 return m_t;
85 }
86
87private:
88 T m_t;
89};
90
91} // detail
92} // beast
93
94#endif