mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-08-01 21:54:28 +02:00
Special case array construction for trivially default-constructible types and array destruction for trivially-destroyable types.
[SVN r81749]
This commit is contained in:
@@ -17,12 +17,32 @@ namespace boost {
|
|||||||
namespace detail {
|
namespace detail {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void array_destroy(T* memory, std::size_t size) {
|
inline void array_destroy(T* memory, std::size_t size) {
|
||||||
|
boost::has_trivial_destructor<T> type;
|
||||||
|
array_destroy(memory, size, type);
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline void array_destroy(T*, std::size_t, boost::true_type) {
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline void array_destroy(T* memory, std::size_t size, boost::false_type) {
|
||||||
for (std::size_t i = size; i > 0; ) {
|
for (std::size_t i = size; i > 0; ) {
|
||||||
memory[--i].~T();
|
memory[--i].~T();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void array_construct(T* memory, std::size_t size) {
|
inline void array_construct(T* memory, std::size_t size) {
|
||||||
|
boost::has_trivial_default_constructor<T> type;
|
||||||
|
array_construct(memory, size, type);
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline void array_construct(T* memory, std::size_t size, boost::true_type) {
|
||||||
|
for (std::size_t i = 0; i < size; i++) {
|
||||||
|
void* p1 = memory + i;
|
||||||
|
::new(p1) T();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline void array_construct(T* memory, std::size_t size, boost::false_type) {
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
try {
|
try {
|
||||||
for (; i < size; i++) {
|
for (; i < size; i++) {
|
||||||
@@ -92,6 +112,14 @@ namespace boost {
|
|||||||
}
|
}
|
||||||
template<typename T>
|
template<typename T>
|
||||||
inline void array_construct_noinit(T* memory, std::size_t size) {
|
inline void array_construct_noinit(T* memory, std::size_t size) {
|
||||||
|
boost::has_trivial_default_constructor<T> type;
|
||||||
|
array_construct_noinit(memory, size, type);
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline void array_construct_noinit(T*, std::size_t, boost::true_type) {
|
||||||
|
}
|
||||||
|
template<typename T>
|
||||||
|
inline void array_construct_noinit(T* memory, std::size_t size, boost::false_type) {
|
||||||
std::size_t i = 0;
|
std::size_t i = 0;
|
||||||
try {
|
try {
|
||||||
for (; i < size; i++) {
|
for (; i < size; i++) {
|
||||||
|
Reference in New Issue
Block a user