]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/beast/core/detail/empty_base_optimization.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / beast / core / detail / empty_base_optimization.hpp
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>
22 struct is_empty_base_optimization_derived
23 : std::integral_constant<bool,
24 std::is_empty<T>::value &&
25 ! boost::is_final<T>::value>
26 {
27 };
28
29 template<class T, int UniqueID = 0,
30 bool isDerived =
31 is_empty_base_optimization_derived<T>::value>
32 class empty_base_optimization : private T
33 {
34 public:
35 empty_base_optimization() = default;
36 empty_base_optimization(empty_base_optimization&&) = default;
37 empty_base_optimization(empty_base_optimization const&) = default;
38 empty_base_optimization& operator=(empty_base_optimization&&) = default;
39 empty_base_optimization& operator=(empty_base_optimization const&) = default;
40
41 template<class Arg1, class... ArgN>
42 explicit
43 empty_base_optimization(Arg1&& arg1, ArgN&&... argn)
44 : T(std::forward<Arg1>(arg1),
45 std::forward<ArgN>(argn)...)
46 {
47 }
48
49 T& member() noexcept
50 {
51 return *this;
52 }
53
54 T const& member() const noexcept
55 {
56 return *this;
57 }
58 };
59
60 //------------------------------------------------------------------------------
61
62 template<
63 class T,
64 int UniqueID
65 >
66 class empty_base_optimization <T, UniqueID, false>
67 {
68 T t_;
69
70 public:
71 empty_base_optimization() = default;
72 empty_base_optimization(empty_base_optimization&&) = default;
73 empty_base_optimization(empty_base_optimization const&) = default;
74 empty_base_optimization& operator=(empty_base_optimization&&) = default;
75 empty_base_optimization& operator=(empty_base_optimization const&) = default;
76
77 template<class Arg1, class... ArgN>
78 explicit
79 empty_base_optimization(Arg1&& arg1, ArgN&&... argn)
80 : t_(std::forward<Arg1>(arg1),
81 std::forward<ArgN>(argn)...)
82 {
83 }
84
85 T& member() noexcept
86 {
87 return t_;
88 }
89
90 T const& member() const noexcept
91 {
92 return t_;
93 }
94 };
95
96 } // detail
97 } // beast
98 } // boost
99
100 #endif