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 template<class U>
19 struct rebind {
20 typedef noinit_adaptor<typename allocator_rebind<A, U>::type> other;
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) { }
34
35 template<class U>
36 noinit_adaptor(U& u) BOOST_NOEXCEPT
37 : A(u) { }
38#endif
39
40 template<class U>
41 noinit_adaptor(const noinit_adaptor<U>& u) BOOST_NOEXCEPT
42 : A(static_cast<const A&>(u)) { }
43
44 template<class U>
45 void construct(U* p) {
46 ::new((void*)p) U;
47 }
48
49#if defined(BOOST_NO_CXX11_ALLOCATOR)
50 template<class U, class V>
51 void construct(U* p, const V& v) {
52 ::new((void*)p) U(v);
53 }
54#endif
55
56 template<class U>
57 void destroy(U* p) {
58 p->~U();
59 }
60};
61
62template<class T, class U>
63inline bool
64operator==(const noinit_adaptor<T>& lhs,
65 const noinit_adaptor<U>& rhs) BOOST_NOEXCEPT
66{
67 return static_cast<const T&>(lhs) == static_cast<const U&>(rhs);
68}
69
70template<class T, class U>
71inline bool
72operator!=(const noinit_adaptor<T>& lhs,
73 const noinit_adaptor<U>& rhs) BOOST_NOEXCEPT
74{
75 return !(lhs == rhs);
76}
77
78template<class A>
79inline noinit_adaptor<A>
80noinit_adapt(const A& a) BOOST_NOEXCEPT
81{
82 return noinit_adaptor<A>(a);
83}
84
85} /* boost */
86
87#endif
88

source code of include/boost/core/noinit_adaptor.hpp