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