Simplify noinit_adaptor using allocator_access

This commit is contained in:
Glen Fernandes 2020-05-23 11:02:06 -04:00
parent 15db54983b
commit 6a33e879dd
2 changed files with 10 additions and 44 deletions

View File

@ -71,8 +71,7 @@ struct noinit_adaptor
: A { : A {
template<class U> template<class U>
struct rebind { struct rebind {
typedef noinit_adaptor<typename std::allocator_traits<A>::template typedef noinit_adaptor<allocator_rebind_t<A, U> > other;
rebind_alloc<U> > other;
}; };
noinit_adaptor() noexcept; noinit_adaptor() noexcept;
@ -86,9 +85,6 @@ struct noinit_adaptor
template<class U> template<class U>
void construct(U* p); void construct(U* p);
template<class U, class V, class... Args>
void construct(U* p, V&& v, Args&&... args);
template<class U> template<class U>
void destroy(U* p); void destroy(U* p);
}; };
@ -121,7 +117,7 @@ noinit_adaptor<A> noinit_adapt(const A& a) noexcept;
[[variablelist [[variablelist
[[Requires][`A` shall be constructible from `U`.]] [[Requires][`A` shall be constructible from `U`.]]
[[Effects][Initializes the `A` base class with [[Effects][Initializes the `A` base class with
`static_cast<const U&>(u)`.]]]]]] `static_cast<const A&>(u)`.]]]]]]
[endsect] [endsect]
@ -131,11 +127,6 @@ noinit_adaptor<A> noinit_adapt(const A& a) noexcept;
[[`template<class U> void construct(U* p);`] [[`template<class U> void construct(U* p);`]
[[variablelist [[variablelist
[[Effects][`::new((void*)p) U`.]]]]] [[Effects][`::new((void*)p) U`.]]]]]
[[`template<class U, class V, class... Args> void construct(U* p, V&& v,
Args&&... args);`]
[[variablelist
[[Effects][`::new(void*)p) U(std::forward<V>(v),
std::forward<Args>(args)...)`.]]]]]
[[`template<class U> void destroy(U* p);`] [[`template<class U> void destroy(U* p);`]
[[variablelist [[variablelist
[[Effects][`p->~U()`.]]]]]] [[Effects][`p->~U()`.]]]]]]

View File

@ -8,14 +8,7 @@ Distributed under the Boost Software License, Version 1.0.
#ifndef BOOST_CORE_NOINIT_ADAPTOR_HPP #ifndef BOOST_CORE_NOINIT_ADAPTOR_HPP
#define BOOST_CORE_NOINIT_ADAPTOR_HPP #define BOOST_CORE_NOINIT_ADAPTOR_HPP
#include <boost/config.hpp> #include <boost/core/allocator_access.hpp>
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
#include <memory>
#endif
#include <new>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
#include <utility>
#endif
namespace boost { namespace boost {
@ -24,12 +17,7 @@ struct noinit_adaptor
: A { : A {
template<class U> template<class U>
struct rebind { struct rebind {
#if !defined(BOOST_NO_CXX11_ALLOCATOR) typedef noinit_adaptor<typename allocator_rebind<A, U>::type> other;
typedef noinit_adaptor<typename std::allocator_traits<A>::template
rebind_alloc<U> > other;
#else
typedef noinit_adaptor<typename A::template rebind<U>::other> other;
#endif
}; };
noinit_adaptor() noinit_adaptor()
@ -43,39 +31,26 @@ struct noinit_adaptor
template<class U> template<class U>
noinit_adaptor(const U& u) BOOST_NOEXCEPT noinit_adaptor(const U& u) BOOST_NOEXCEPT
: A(u) { } : A(u) { }
template<class U>
noinit_adaptor(U& u) BOOST_NOEXCEPT
: A(u) { }
#endif #endif
template<class U> template<class U>
noinit_adaptor(const noinit_adaptor<U>& u) BOOST_NOEXCEPT noinit_adaptor(const noinit_adaptor<U>& u) BOOST_NOEXCEPT
: A(static_cast<const U&>(u)) { } : A(static_cast<const A&>(u)) { }
template<class U> template<class U>
void construct(U* p) { void construct(U* p) {
::new((void*)p) U; ::new((void*)p) U;
} }
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) #if defined(BOOST_NO_CXX11_ALLOCATOR)
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template<class U, class V, class... Args>
void construct(U* p, V&& v, Args&&... args) {
::new((void*)p) U(std::forward<V>(v), std::forward<Args>(args)...);
}
#else
template<class U, class V>
void construct(U* p, V&& v) {
::new((void*)p) U(std::forward<V>(v));
}
#endif
#else
template<class U, class V> template<class U, class V>
void construct(U* p, const V& v) { void construct(U* p, const V& v) {
::new((void*)p) U(v); ::new((void*)p) U(v);
} }
template<class U, class V>
void construct(U* p, V& v) {
::new((void*)p) U(v);
}
#endif #endif
template<class U> template<class U>