mirror of
https://github.com/boostorg/multi_array.git
synced 2026-01-19 16:32:11 +00:00
Use alloc_construct utilities from Boost.Core
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
#include "boost/multi_array/subarray.hpp"
|
||||
#include "boost/multi_array/multi_array_ref.hpp"
|
||||
#include "boost/multi_array/algorithm.hpp"
|
||||
#include "boost/multi_array/allocators.hpp"
|
||||
#include "boost/core/alloc_construct.hpp"
|
||||
#include "boost/core/empty_value.hpp"
|
||||
#include "boost/array.hpp"
|
||||
#include "boost/mpl/if.hpp"
|
||||
@@ -545,12 +545,12 @@ private:
|
||||
base_ = allocator().allocate(this->num_elements());
|
||||
this->set_base_ptr(base_);
|
||||
allocated_elements_ = this->num_elements();
|
||||
detail::multi_array::construct(allocator(),base_,base_+allocated_elements_);
|
||||
boost::alloc_construct_n(allocator(),base_,allocated_elements_);
|
||||
}
|
||||
|
||||
void deallocate_space() {
|
||||
if(base_) {
|
||||
detail::multi_array::destroy(allocator(),base_,base_+allocated_elements_);
|
||||
boost::alloc_destroy_n(allocator(),base_,allocated_elements_);
|
||||
allocator().deallocate(base_,allocated_elements_);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
// Copyright 2018 Glen Joseph Fernandes
|
||||
// (glenjofe@gmail.com)
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#ifndef BOOST_MULTI_ARRAY_ALLOCATORS_HPP
|
||||
#define BOOST_MULTI_ARRAY_ALLOCATORS_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
#include <memory>
|
||||
#else
|
||||
#include <new>
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
namespace multi_array {
|
||||
|
||||
template<class A, class T>
|
||||
inline void destroy(A& allocator, T* ptr, T* end)
|
||||
{
|
||||
for (; ptr != end; ++ptr) {
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
std::allocator_traits<A>::destroy(allocator,ptr);
|
||||
#else
|
||||
ptr->~T();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
template<class A, class T>
|
||||
inline void construct(A& allocator, T* ptr)
|
||||
{
|
||||
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
|
||||
std::allocator_traits<A>::construct(allocator,ptr);
|
||||
#else
|
||||
::new(static_cast<void*>(ptr)) T();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_EXCEPTIONS)
|
||||
template<class A, class T>
|
||||
inline void construct(A& allocator, T* ptr, T* end)
|
||||
{
|
||||
T* start = ptr;
|
||||
try {
|
||||
for (; ptr != end; ++ptr) {
|
||||
boost::detail::multi_array::construct(allocator,ptr);
|
||||
}
|
||||
} catch (...) {
|
||||
boost::detail::multi_array::destroy(allocator,start,ptr);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#else
|
||||
template<class A, class T>
|
||||
inline void construct(A& allocator, T* ptr, T* end)
|
||||
{
|
||||
for (; ptr != end; ++ptr) {
|
||||
boost::detail::multi_array::construct(allocator,ptr);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // multi_array
|
||||
} // detail
|
||||
} // boost
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user