2012-11-06 14:17:32 +00:00
|
|
|
/*
|
|
|
|
* 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_DELETER_HPP
|
|
|
|
#define BOOST_SMART_PTR_DETAIL_ARRAY_DELETER_HPP
|
|
|
|
|
|
|
|
#include <boost/config.hpp>
|
2012-11-07 14:42:10 +00:00
|
|
|
#include <boost/smart_ptr/detail/array_helper.hpp>
|
2012-11-06 14:17:32 +00:00
|
|
|
#include <cstddef>
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
namespace detail {
|
|
|
|
template<typename T>
|
|
|
|
class array_deleter {
|
|
|
|
public:
|
|
|
|
array_deleter()
|
|
|
|
: size(0) {
|
|
|
|
}
|
|
|
|
~array_deleter() {
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
void construct(T* memory, std::size_t count) {
|
|
|
|
for (object = memory; size < count; size++) {
|
2012-11-07 14:42:10 +00:00
|
|
|
array_helper<T>::create(object[size]);
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
|
|
|
|
template<typename... Args>
|
|
|
|
void construct(T* memory, std::size_t count, Args&&... args) {
|
|
|
|
for (object = memory; size < count; size++) {
|
2012-11-07 14:42:10 +00:00
|
|
|
array_helper<T>::create(object[size], args...);
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
void construct_noinit(T* memory, std::size_t count) {
|
|
|
|
for (object = memory; size < count; size++) {
|
2012-11-07 14:42:10 +00:00
|
|
|
array_helper<T>::create_noinit(object[size]);
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void operator()(T*) {
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
void destroy() {
|
|
|
|
while (size > 0) {
|
2012-11-07 14:42:10 +00:00
|
|
|
array_helper<T>::destroy(object[--size]);
|
2012-11-06 14:17:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
std::size_t size;
|
|
|
|
T* object;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|