]>
Commit | Line | Data |
---|---|---|
92f5a8d4 TL |
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 | ||
20effc67 | 11 | #include <boost/core/allocator_access.hpp> |
92f5a8d4 TL |
12 | |
13 | namespace boost { | |
14 | ||
15 | template<class A> | |
16 | struct noinit_adaptor | |
17 | : A { | |
18 | template<class U> | |
19 | struct rebind { | |
20effc67 | 20 | typedef noinit_adaptor<typename allocator_rebind<A, U>::type> other; |
92f5a8d4 TL |
21 | }; |
22 | ||
23 | noinit_adaptor() | |
24 | : A() { } | |
25 | ||
26 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) | |
27 | template<class U> | |
28 | noinit_adaptor(U&& u) BOOST_NOEXCEPT | |
29 | : A(std::forward<U>(u)) { } | |
30 | #else | |
31 | template<class U> | |
32 | noinit_adaptor(const U& u) BOOST_NOEXCEPT | |
33 | : A(u) { } | |
20effc67 TL |
34 | |
35 | template<class U> | |
36 | noinit_adaptor(U& u) BOOST_NOEXCEPT | |
37 | : A(u) { } | |
92f5a8d4 TL |
38 | #endif |
39 | ||
40 | template<class U> | |
41 | noinit_adaptor(const noinit_adaptor<U>& u) BOOST_NOEXCEPT | |
20effc67 | 42 | : A(static_cast<const A&>(u)) { } |
92f5a8d4 TL |
43 | |
44 | template<class U> | |
45 | void construct(U* p) { | |
46 | ::new((void*)p) U; | |
47 | } | |
48 | ||
20effc67 | 49 | #if defined(BOOST_NO_CXX11_ALLOCATOR) |
92f5a8d4 TL |
50 | template<class U, class V> |
51 | void construct(U* p, const V& v) { | |
52 | ::new((void*)p) U(v); | |
53 | } | |
92f5a8d4 TL |
54 | #endif |
55 | ||
56 | template<class U> | |
57 | void destroy(U* p) { | |
58 | p->~U(); | |
1e59de90 | 59 | (void)p; |
92f5a8d4 TL |
60 | } |
61 | }; | |
62 | ||
63 | template<class T, class U> | |
64 | inline bool | |
65 | operator==(const noinit_adaptor<T>& lhs, | |
66 | const noinit_adaptor<U>& rhs) BOOST_NOEXCEPT | |
67 | { | |
68 | return static_cast<const T&>(lhs) == static_cast<const U&>(rhs); | |
69 | } | |
70 | ||
71 | template<class T, class U> | |
72 | inline bool | |
73 | operator!=(const noinit_adaptor<T>& lhs, | |
74 | const noinit_adaptor<U>& rhs) BOOST_NOEXCEPT | |
75 | { | |
76 | return !(lhs == rhs); | |
77 | } | |
78 | ||
79 | template<class A> | |
80 | inline noinit_adaptor<A> | |
81 | noinit_adapt(const A& a) BOOST_NOEXCEPT | |
82 | { | |
83 | return noinit_adaptor<A>(a); | |
84 | } | |
85 | ||
86 | } /* boost */ | |
87 | ||
88 | #endif |