]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/core/noinit_adaptor.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / core / noinit_adaptor.hpp
1 /*
2 Copyright 2019 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
7 */
8 #ifndef BOOST_CORE_NOINIT_ADAPTOR_HPP
9 #define BOOST_CORE_NOINIT_ADAPTOR_HPP
10
11 #include <boost/config.hpp>
12 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
13 #include <memory>
14 #endif
15 #include <new>
16 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
17 #include <utility>
18 #endif
19
20 namespace boost {
21
22 template<class A>
23 struct noinit_adaptor
24 : A {
25 template<class U>
26 struct rebind {
27 #if !defined(BOOST_NO_CXX11_ALLOCATOR)
28 typedef noinit_adaptor<typename std::allocator_traits<A>::template
29 rebind_alloc<U> > other;
30 #else
31 typedef noinit_adaptor<typename A::template rebind<U>::other> other;
32 #endif
33 };
34
35 noinit_adaptor()
36 : A() { }
37
38 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
39 template<class U>
40 noinit_adaptor(U&& u) BOOST_NOEXCEPT
41 : A(std::forward<U>(u)) { }
42 #else
43 template<class U>
44 noinit_adaptor(const U& u) BOOST_NOEXCEPT
45 : A(u) { }
46 #endif
47
48 template<class U>
49 noinit_adaptor(const noinit_adaptor<U>& u) BOOST_NOEXCEPT
50 : A(static_cast<const U&>(u)) { }
51
52 template<class U>
53 void construct(U* p) {
54 ::new((void*)p) U;
55 }
56
57 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
58 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
59 template<class U, class V, class... Args>
60 void construct(U* p, V&& v, Args&&... args) {
61 ::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
62 }
63 #else
64 template<class U, class V>
65 void construct(U* p, V&& v) {
66 ::new((void*)p) U(std::forward<V>(v));
67 }
68 #endif
69 #else
70 template<class U, class V>
71 void construct(U* p, const V& v) {
72 ::new((void*)p) U(v);
73 }
74
75 template<class U, class V>
76 void construct(U* p, V& v) {
77 ::new((void*)p) U(v);
78 }
79 #endif
80
81 template<class U>
82 void destroy(U* p) {
83 p->~U();
84 }
85 };
86
87 template<class T, class U>
88 inline bool
89 operator==(const noinit_adaptor<T>& lhs,
90 const noinit_adaptor<U>& rhs) BOOST_NOEXCEPT
91 {
92 return static_cast<const T&>(lhs) == static_cast<const U&>(rhs);
93 }
94
95 template<class T, class U>
96 inline bool
97 operator!=(const noinit_adaptor<T>& lhs,
98 const noinit_adaptor<U>& rhs) BOOST_NOEXCEPT
99 {
100 return !(lhs == rhs);
101 }
102
103 template<class A>
104 inline noinit_adaptor<A>
105 noinit_adapt(const A& a) BOOST_NOEXCEPT
106 {
107 return noinit_adaptor<A>(a);
108 }
109
110 } /* boost */
111
112 #endif