mirror of
https://github.com/boostorg/core.git
synced 2025-11-29 22:00:17 +01:00
Add allocator_construct_n to allocator_access and deprecate alloc_construct
This commit is contained in:
@@ -8,6 +8,9 @@ Distributed under the Boost Software License, Version 1.0.
|
||||
#ifndef BOOST_CORE_ALLOC_CONSTRUCT_HPP
|
||||
#define BOOST_CORE_ALLOC_CONSTRUCT_HPP
|
||||
|
||||
/*
|
||||
This functionality is now in <boost/core/allocator_access.hpp>.
|
||||
*/
|
||||
#include <boost/core/noinit_adaptor.hpp>
|
||||
|
||||
namespace boost {
|
||||
@@ -23,56 +26,9 @@ template<class A, class T>
|
||||
inline void
|
||||
alloc_destroy_n(A& a, T* p, std::size_t n)
|
||||
{
|
||||
while (n > 0) {
|
||||
boost::allocator_destroy(a, p + --n);
|
||||
}
|
||||
boost::allocator_destroy_n(a, p, n);
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_destroy(noinit_adaptor<A>&, T* p)
|
||||
{
|
||||
p->~T();
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_destroy_n(noinit_adaptor<A>&, T* p, std::size_t n)
|
||||
{
|
||||
while (n > 0) {
|
||||
p[--n].~T();
|
||||
}
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<class A, class T>
|
||||
class alloc_destroyer {
|
||||
public:
|
||||
alloc_destroyer(A& a, T* p) BOOST_NOEXCEPT
|
||||
: a_(a),
|
||||
p_(p),
|
||||
n_(0) { }
|
||||
|
||||
~alloc_destroyer() {
|
||||
boost::alloc_destroy_n(a_, p_, n_);
|
||||
}
|
||||
|
||||
std::size_t& size() BOOST_NOEXCEPT {
|
||||
return n_;
|
||||
}
|
||||
|
||||
private:
|
||||
alloc_destroyer(const alloc_destroyer&);
|
||||
alloc_destroyer& operator=(const alloc_destroyer&);
|
||||
|
||||
A& a_;
|
||||
T* p_;
|
||||
std::size_t n_;
|
||||
};
|
||||
|
||||
} /* detail */
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct(A& a, T* p)
|
||||
@@ -117,51 +73,21 @@ template<class A, class T>
|
||||
inline void
|
||||
alloc_construct_n(A& a, T* p, std::size_t n)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; ++i) {
|
||||
boost::allocator_construct(a, p + i);
|
||||
}
|
||||
hold.size() = 0;
|
||||
boost::allocator_construct_n(a, p, n);
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct_n(A& a, T* p, std::size_t n, const T* l, std::size_t m)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; ++i) {
|
||||
boost::allocator_construct(a, p + i, l[i % m]);
|
||||
}
|
||||
hold.size() = 0;
|
||||
boost::allocator_construct_n(a, p, n, l, m);
|
||||
}
|
||||
|
||||
template<class A, class T, class I>
|
||||
inline void
|
||||
alloc_construct_n(A& a, T* p, std::size_t n, I b)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; void(++i), void(++b)) {
|
||||
boost::allocator_construct(a, p + i, *b);
|
||||
}
|
||||
hold.size() = 0;
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct(noinit_adaptor<A>&, T* p)
|
||||
{
|
||||
::new(static_cast<void*>(p)) T;
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
alloc_construct_n(noinit_adaptor<A>& a, T* p, std::size_t n)
|
||||
{
|
||||
detail::alloc_destroyer<noinit_adaptor<A>, T> hold(a, p);
|
||||
for (std::size_t& i = hold.size(); i < n; ++i) {
|
||||
::new(static_cast<void*>(p + i)) T;
|
||||
}
|
||||
hold.size() = 0;
|
||||
boost::allocator_construct_n(a, p, n, b);
|
||||
}
|
||||
|
||||
} /* boost */
|
||||
|
||||
@@ -714,6 +714,75 @@ allocator_select_on_container_copy_construction(const A& a)
|
||||
return a;
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
allocator_destroy_n(A& a, T* p, std::size_t n)
|
||||
{
|
||||
while (n > 0) {
|
||||
boost::allocator_destroy(a, p + --n);
|
||||
}
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
|
||||
template<class A, class T>
|
||||
class alloc_destroyer {
|
||||
public:
|
||||
alloc_destroyer(A& a, T* p) BOOST_NOEXCEPT
|
||||
: a_(a), p_(p), n_(0) { }
|
||||
|
||||
~alloc_destroyer() {
|
||||
boost::allocator_destroy_n(a_, p_, n_);
|
||||
}
|
||||
|
||||
std::size_t& size() BOOST_NOEXCEPT {
|
||||
return n_;
|
||||
}
|
||||
|
||||
private:
|
||||
alloc_destroyer(const alloc_destroyer&);
|
||||
alloc_destroyer& operator=(const alloc_destroyer&);
|
||||
|
||||
A& a_;
|
||||
T* p_;
|
||||
std::size_t n_;
|
||||
};
|
||||
|
||||
} /* detail */
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
allocator_construct_n(A& a, T* p, std::size_t n)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> d(a, p);
|
||||
for (std::size_t& i = d.size(); i < n; ++i) {
|
||||
boost::allocator_construct(a, p + i);
|
||||
}
|
||||
d.size() = 0;
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void
|
||||
allocator_construct_n(A& a, T* p, std::size_t n, const T* l, std::size_t m)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> d(a, p);
|
||||
for (std::size_t& i = d.size(); i < n; ++i) {
|
||||
boost::allocator_construct(a, p + i, l[i % m]);
|
||||
}
|
||||
d.size() = 0;
|
||||
}
|
||||
|
||||
template<class A, class T, class I>
|
||||
inline void
|
||||
allocator_construct_n(A& a, T* p, std::size_t n, I b)
|
||||
{
|
||||
detail::alloc_destroyer<A, T> d(a, p);
|
||||
for (std::size_t& i = d.size(); i < n; void(++i), void(++b)) {
|
||||
boost::allocator_construct(a, p + i, *b);
|
||||
}
|
||||
d.size() = 0;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
||||
template<class A>
|
||||
using allocator_value_type_t = typename allocator_value_type<A>::type;
|
||||
|
||||
Reference in New Issue
Block a user