forked from boostorg/smart_ptr
Refactoring in detail array_deleter before adding support for special-casing trivially default-constructible construction and trivially destroyable destruction.
[SVN r81748]
This commit is contained in:
1 parent
6c2ed927e4
commit
1209531fe0
4 files changed
+145
-140
No files matched your search
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Glen Joseph Fernandes
|
||||
* glenfe at live dot com
|
||||
*
|
||||
* Distributed under the Boost Software License,
|
||||
* Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
* or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#ifndef BOOST_SMART_PTR_DETAIL_ARRAY_UTILITY_HPP
|
||||
#define BOOST_SMART_PTR_DETAIL_ARRAY_UTILITY_HPP
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/type_traits/has_trivial_constructor.hpp>
|
||||
#include <boost/type_traits/has_trivial_destructor.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
inline void array_destroy(T* memory, std::size_t size) {
|
||||
for (std::size_t i = size; i > 0; ) {
|
||||
memory[--i].~T();
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
inline void array_construct(T* memory, std::size_t size) {
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T();
|
||||
}
|
||||
} catch (...) {
|
||||
array_destroy(memory, i);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#if defined(BOOST_HAS_RVALUE_REFS)
|
||||
template<typename T>
|
||||
inline void array_construct(T* memory, std::size_t size, T value) {
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T(value);
|
||||
}
|
||||
} catch (...) {
|
||||
array_destroy(memory, i);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#if defined(BOOST_HAS_VARIADIC_TMPL)
|
||||
template<typename T, typename... Args>
|
||||
inline void array_construct(T* memory, std::size_t size, Args... args) {
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T(args...);
|
||||
}
|
||||
} catch (...) {
|
||||
array_destroy(memory, i);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
template<typename T>
|
||||
inline void array_construct_list(T* memory, std::size_t size, const T* list) {
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T(list[i]);
|
||||
}
|
||||
} catch (...) {
|
||||
array_destroy(memory, i);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
inline void array_construct_list(T* memory, std::size_t size, const T* list, std::size_t n) {
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T(list[i % n]);
|
||||
}
|
||||
} catch (...) {
|
||||
array_destroy(memory, i);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
template<typename T>
|
||||
inline void array_construct_noinit(T* memory, std::size_t size) {
|
||||
std::size_t i = 0;
|
||||
try {
|
||||
for (; i < size; i++) {
|
||||
void* p1 = memory + i;
|
||||
::new(p1) T;
|
||||
}
|
||||
} catch (...) {
|
||||
array_destroy(memory, i);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user