Merge from branch 'develop' into 'master'

1. Update make_shared for arrays to conform to N3870

Merging 630e4f49f3^..87e5debdc2 from develop to master
This commit is contained in:
Glen Fernandes
2014-01-23 20:40:46 -08:00
parent 04f456f86d
commit 83b3b703e0
32 changed files with 1124 additions and 2082 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -9,14 +9,11 @@
#ifndef BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP #ifndef BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP
#define BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP #define BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/detail/allocate_array_helper.hpp> #include <boost/smart_ptr/detail/allocate_array_helper.hpp>
#include <boost/smart_ptr/detail/array_deleter.hpp> #include <boost/smart_ptr/detail/array_deleter.hpp>
#include <boost/smart_ptr/detail/array_traits.hpp> #include <boost/smart_ptr/detail/array_traits.hpp>
#include <boost/smart_ptr/detail/sp_if_array.hpp> #include <boost/smart_ptr/detail/sp_if_array.hpp>
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) #include <boost/type_traits/remove_cv.hpp>
#include <initializer_list>
#endif
namespace boost { namespace boost {
template<typename T, typename A> template<typename T, typename A>
@ -24,222 +21,125 @@ namespace boost {
allocate_shared(const A& allocator, std::size_t size) { allocate_shared(const A& allocator, std::size_t size) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef typename boost::remove_cv<T2>::type T3;
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
std::size_t n1 = size * boost::detail::array_total<T1>::size; std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2); boost::detail::allocate_array_helper<A, T3[]> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1); boost::detail::array_deleter<T3[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2; typedef boost::detail::array_deleter<T3[]>* D2;
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2); d2->init(p2);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<typename T, typename A, typename... Args>
inline typename boost::detail::sp_if_array<T>::type
allocate_shared(const A& allocator, std::size_t size, Args&&... args) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2;
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2, boost::detail::sp_forward<Args>(args)...);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T, typename A, typename... Args>
inline typename boost::detail::sp_if_size_array<T>::type
allocate_shared(const A& allocator, Args&&... args) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
enum {
N = boost::detail::array_total<T>::size
};
T1* p1 = 0;
T2* p2 = 0;
boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2);
boost::detail::array_deleter<T2[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2;
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2, boost::detail::sp_forward<Args>(args)...);
return boost::shared_ptr<T>(s1, p1);
}
#endif
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
template<typename T, typename A> template<typename T, typename A>
inline typename boost::detail::sp_if_size_array<T>::type inline typename boost::detail::sp_if_size_array<T>::type
allocate_shared(const A& allocator, const T& list) { allocate_shared(const A& allocator) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3; typedef typename boost::remove_cv<T2>::type T3;
enum { enum {
N = boost::detail::array_total<T>::size N = boost::detail::array_total<T>::size
}; };
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
T3* p3 = 0; boost::detail::allocate_array_helper<A, T3[N]> a1(allocator, &p2);
boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2); boost::detail::array_deleter<T3[N]> d1;
boost::detail::array_deleter<T2[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2; typedef boost::detail::array_deleter<T3[N]>* D2;
p3 = reinterpret_cast<T3*>(list);
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init_list(p2, p3); d2->init(p2);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
template<typename T, typename A> template<typename T, typename A>
inline typename boost::detail::sp_if_array<T>::type inline typename boost::detail::sp_if_array<T>::type
allocate_shared(const A& allocator, std::size_t size, allocate_shared(const A& allocator, std::size_t size,
const typename boost::detail::array_inner<T>::type& list) { const typename boost::detail::array_inner<T>::type& value) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3; typedef typename boost::remove_cv<T2>::type T3;
typedef const T2 T4;
enum { enum {
M = boost::detail::array_total<T1>::size M = boost::detail::array_total<T1>::size
}; };
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
T3* p3 = 0; T4* p3 = reinterpret_cast<T4*>(&value);
std::size_t n1 = M * size; std::size_t n1 = M * size;
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2); boost::detail::allocate_array_helper<A, T3[]> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1); boost::detail::array_deleter<T3[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2; typedef boost::detail::array_deleter<T3[]>* D2;
p3 = reinterpret_cast<T3*>(list);
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->template init_list<M>(p2, p3); d2->template init<M>(p2, p3);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
template<typename T, typename A> template<typename T, typename A>
inline typename boost::detail::sp_if_size_array<T>::type inline typename boost::detail::sp_if_size_array<T>::type
allocate_shared(const A& allocator, allocate_shared(const A& allocator,
const typename boost::detail::array_inner<T>::type& list) { const typename boost::detail::array_inner<T>::type& value) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3; typedef typename boost::remove_cv<T2>::type T3;
typedef const T2 T4;
enum { enum {
M = boost::detail::array_total<T1>::size, M = boost::detail::array_total<T1>::size,
N = boost::detail::array_total<T>::size N = boost::detail::array_total<T>::size
}; };
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
T3* p3 = 0; T4* p3 = reinterpret_cast<T4*>(&value);
boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2); boost::detail::allocate_array_helper<A, T3[N]> a1(allocator, &p2);
boost::detail::array_deleter<T2[N]> d1; boost::detail::array_deleter<T3[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2; typedef boost::detail::array_deleter<T3[N]>* D2;
p3 = reinterpret_cast<T3*>(list);
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->template init_list<M>(p2, p3); d2->template init<M>(p2, p3);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
template<typename T, typename A>
inline typename boost::detail::sp_if_array<T>::type
allocate_shared(const A& allocator,
std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n1 = list.size() * boost::detail::array_total<T1>::size;
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init_list(p2, p3);
return boost::shared_ptr<T>(s1, p1);
}
#endif
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<typename T, typename A>
inline typename boost::detail::sp_if_array<T>::type
allocate_shared(const A& allocator, std::size_t size,
typename boost::detail::array_base<T>::type&& value) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2;
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2, boost::detail::sp_forward<T2>(value));
return boost::shared_ptr<T>(s1, p1);
}
template<typename T, typename A>
inline typename boost::detail::sp_if_size_array<T>::type
allocate_shared(const A& allocator,
typename boost::detail::array_base<T>::type&& value) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
enum {
N = boost::detail::array_total<T>::size
};
T1* p1 = 0;
T2* p2 = 0;
boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2);
boost::detail::array_deleter<T2[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2;
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2, boost::detail::sp_forward<T2>(value));
return boost::shared_ptr<T>(s1, p1);
}
#endif
#endif
template<typename T, typename A> template<typename T, typename A>
inline typename boost::detail::sp_if_array<T>::type inline typename boost::detail::sp_if_array<T>::type
allocate_shared_noinit(const A& allocator, std::size_t size) { allocate_shared_noinit(const A& allocator, std::size_t size) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef typename boost::remove_cv<T2>::type T3;
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
std::size_t n1 = size * boost::detail::array_total<T1>::size; std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2); boost::detail::allocate_array_helper<A, T3[]> a1(allocator, n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1); boost::detail::array_deleter<T3[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2; typedef boost::detail::array_deleter<T3[]>* D2;
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->noinit(p2); d2->noinit(p2);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
template<typename T, typename A> template<typename T, typename A>
inline typename boost::detail::sp_if_size_array<T>::type inline typename boost::detail::sp_if_size_array<T>::type
allocate_shared_noinit(const A& allocator) { allocate_shared_noinit(const A& allocator) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef typename boost::remove_cv<T2>::type T3;
enum { enum {
N = boost::detail::array_total<T>::size N = boost::detail::array_total<T>::size
}; };
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2); boost::detail::allocate_array_helper<A, T3[N]> a1(allocator, &p2);
boost::detail::array_deleter<T2[N]> d1; boost::detail::array_deleter<T3[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2; typedef boost::detail::array_deleter<T3[N]>* D2;
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->noinit(p2); d2->noinit(p2);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -15,12 +15,15 @@ namespace boost {
namespace detail { namespace detail {
template<typename A, typename T, typename Y = char> template<typename A, typename T, typename Y = char>
class allocate_array_helper; class allocate_array_helper;
template<typename A, typename T, typename Y> template<typename A, typename T, typename Y>
class allocate_array_helper<A, T[], Y> { class allocate_array_helper<A, T[], Y> {
template<typename A9, typename T9, typename Y9> template<typename A9, typename T9, typename Y9>
friend class allocate_array_helper; friend class allocate_array_helper;
typedef typename A::template rebind<Y> ::other A2; typedef typename A::template rebind<Y> ::other A2;
typedef typename A::template rebind<char>::other A3; typedef typename A::template rebind<char>::other A3;
public: public:
typedef typename A2::value_type value_type; typedef typename A2::value_type value_type;
typedef typename A2::pointer pointer; typedef typename A2::pointer pointer;
@ -29,30 +32,37 @@ namespace boost {
typedef typename A2::const_reference const_reference; typedef typename A2::const_reference const_reference;
typedef typename A2::size_type size_type; typedef typename A2::size_type size_type;
typedef typename A2::difference_type difference_type; typedef typename A2::difference_type difference_type;
template<typename U> template<typename U>
struct rebind { struct rebind {
typedef allocate_array_helper<A, T[], U> other; typedef allocate_array_helper<A, T[], U> other;
}; };
allocate_array_helper(const A& allocator_, std::size_t size_, T** data_) allocate_array_helper(const A& allocator_, std::size_t size_, T** data_)
: allocator(allocator_), : allocator(allocator_),
size(sizeof(T) * size_), size(sizeof(T) * size_),
data(data_) { data(data_) {
} }
template<class U> template<class U>
allocate_array_helper(const allocate_array_helper<A, T[], U>& other) allocate_array_helper(const allocate_array_helper<A, T[], U>& other)
: allocator(other.allocator), : allocator(other.allocator),
size(other.size), size(other.size),
data(other.data) { data(other.data) {
} }
pointer address(reference value) const { pointer address(reference value) const {
return allocator.address(value); return allocator.address(value);
} }
const_pointer address(const_reference value) const { const_pointer address(const_reference value) const {
return allocator.address(value); return allocator.address(value);
} }
size_type max_size() const { size_type max_size() const {
return allocator.max_size(); return allocator.max_size();
} }
pointer allocate(size_type count, const void* value = 0) { pointer allocate(size_type count, const void* value = 0) {
std::size_t a1 = boost::alignment_of<T>::value; std::size_t a1 = boost::alignment_of<T>::value;
std::size_t n1 = count * sizeof(Y) + a1 - 1; std::size_t n1 = count * sizeof(Y) + a1 - 1;
@ -64,37 +74,46 @@ namespace boost {
*data = reinterpret_cast<T*>(p2); *data = reinterpret_cast<T*>(p2);
return reinterpret_cast<Y*>(p1); return reinterpret_cast<Y*>(p1);
} }
void deallocate(pointer memory, size_type count) { void deallocate(pointer memory, size_type count) {
std::size_t a1 = boost::alignment_of<T>::value; std::size_t a1 = boost::alignment_of<T>::value;
std::size_t n1 = count * sizeof(Y) + a1 - 1; std::size_t n1 = count * sizeof(Y) + a1 - 1;
char* p1 = reinterpret_cast<char*>(memory); char* p1 = reinterpret_cast<char*>(memory);
A3(allocator).deallocate(p1, n1 + size); A3(allocator).deallocate(p1, n1 + size);
} }
void construct(pointer memory, const Y& value) { void construct(pointer memory, const Y& value) {
allocator.construct(memory, value); allocator.construct(memory, value);
} }
void destroy(pointer memory) { void destroy(pointer memory) {
allocator.destroy(memory); allocator.destroy(memory);
} }
template<typename U> template<typename U>
bool operator==(const allocate_array_helper<A, T[], U>& other) const { bool operator==(const allocate_array_helper<A, T[], U>& other) const {
return allocator == other.allocator; return allocator == other.allocator;
} }
template<typename U> template<typename U>
bool operator!=(const allocate_array_helper<A, T[], U>& other) const { bool operator!=(const allocate_array_helper<A, T[], U>& other) const {
return !(*this == other); return !(*this == other);
} }
private: private:
A2 allocator; A2 allocator;
std::size_t size; std::size_t size;
T** data; T** data;
}; };
template<typename A, typename T, std::size_t N, typename Y> template<typename A, typename T, std::size_t N, typename Y>
class allocate_array_helper<A, T[N], Y> { class allocate_array_helper<A, T[N], Y> {
template<typename A9, typename T9, typename Y9> template<typename A9, typename T9, typename Y9>
friend class allocate_array_helper; friend class allocate_array_helper;
typedef typename A::template rebind<Y> ::other A2; typedef typename A::template rebind<Y> ::other A2;
typedef typename A::template rebind<char>::other A3; typedef typename A::template rebind<char>::other A3;
public: public:
typedef typename A2::value_type value_type; typedef typename A2::value_type value_type;
typedef typename A2::pointer pointer; typedef typename A2::pointer pointer;
@ -103,28 +122,35 @@ namespace boost {
typedef typename A2::const_reference const_reference; typedef typename A2::const_reference const_reference;
typedef typename A2::size_type size_type; typedef typename A2::size_type size_type;
typedef typename A2::difference_type difference_type; typedef typename A2::difference_type difference_type;
template<typename U> template<typename U>
struct rebind { struct rebind {
typedef allocate_array_helper<A, T[N], U> other; typedef allocate_array_helper<A, T[N], U> other;
}; };
allocate_array_helper(const A& allocator_, T** data_) allocate_array_helper(const A& allocator_, T** data_)
: allocator(allocator_), : allocator(allocator_),
data(data_) { data(data_) {
} }
template<class U> template<class U>
allocate_array_helper(const allocate_array_helper<A, T[N], U>& other) allocate_array_helper(const allocate_array_helper<A, T[N], U>& other)
: allocator(other.allocator), : allocator(other.allocator),
data(other.data) { data(other.data) {
} }
pointer address(reference value) const { pointer address(reference value) const {
return allocator.address(value); return allocator.address(value);
} }
const_pointer address(const_reference value) const { const_pointer address(const_reference value) const {
return allocator.address(value); return allocator.address(value);
} }
size_type max_size() const { size_type max_size() const {
return allocator.max_size(); return allocator.max_size();
} }
pointer allocate(size_type count, const void* value = 0) { pointer allocate(size_type count, const void* value = 0) {
std::size_t a1 = boost::alignment_of<T>::value; std::size_t a1 = boost::alignment_of<T>::value;
std::size_t n1 = count * sizeof(Y) + a1 - 1; std::size_t n1 = count * sizeof(Y) + a1 - 1;
@ -136,30 +162,37 @@ namespace boost {
*data = reinterpret_cast<T*>(p2); *data = reinterpret_cast<T*>(p2);
return reinterpret_cast<Y*>(p1); return reinterpret_cast<Y*>(p1);
} }
void deallocate(pointer memory, size_type count) { void deallocate(pointer memory, size_type count) {
std::size_t a1 = boost::alignment_of<T>::value; std::size_t a1 = boost::alignment_of<T>::value;
std::size_t n1 = count * sizeof(Y) + a1 - 1; std::size_t n1 = count * sizeof(Y) + a1 - 1;
char* p1 = reinterpret_cast<char*>(memory); char* p1 = reinterpret_cast<char*>(memory);
A3(allocator).deallocate(p1, n1 + N1); A3(allocator).deallocate(p1, n1 + N1);
} }
void construct(pointer memory, const Y& value) { void construct(pointer memory, const Y& value) {
allocator.construct(memory, value); allocator.construct(memory, value);
} }
void destroy(pointer memory) { void destroy(pointer memory) {
allocator.destroy(memory); allocator.destroy(memory);
} }
template<typename U> template<typename U>
bool operator==(const allocate_array_helper<A, T[N], U>& other) const { bool operator==(const allocate_array_helper<A, T[N], U>& other) const {
return allocator == other.allocator; return allocator == other.allocator;
} }
template<typename U> template<typename U>
bool operator!=(const allocate_array_helper<A, T[N], U>& other) const { bool operator!=(const allocate_array_helper<A, T[N], U>& other) const {
return !(*this == other); return !(*this == other);
} }
private: private:
enum { enum {
N1 = N * sizeof(T) N1 = N * sizeof(T)
}; };
A2 allocator; A2 allocator;
T** data; T** data;
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -9,13 +9,14 @@
#ifndef BOOST_SMART_PTR_DETAIL_ARRAY_DELETER_HPP #ifndef BOOST_SMART_PTR_DETAIL_ARRAY_DELETER_HPP
#define BOOST_SMART_PTR_DETAIL_ARRAY_DELETER_HPP #define BOOST_SMART_PTR_DETAIL_ARRAY_DELETER_HPP
#include <boost/smart_ptr/detail/array_traits.hpp>
#include <boost/smart_ptr/detail/array_utility.hpp> #include <boost/smart_ptr/detail/array_utility.hpp>
#include <boost/smart_ptr/detail/sp_forward.hpp>
namespace boost { namespace boost {
namespace detail { namespace detail {
template<typename T> template<typename T>
class array_deleter; class array_deleter;
template<typename T> template<typename T>
class array_deleter<T[]> { class array_deleter<T[]> {
public: public:
@ -23,98 +24,77 @@ namespace boost {
: size(size_), : size(size_),
object(0) { object(0) {
} }
~array_deleter() { ~array_deleter() {
if (object) { if (object) {
array_destroy(object, size); array_destroy(object, size);
} }
} }
void init(T* memory) { void init(T* memory) {
array_init(memory, size); array_init(memory, size);
object = memory; object = memory;
} }
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
void init(T* memory, T&& value) { template<std::size_t N>
array_init_value(memory, size, sp_forward<T>(value)); void init(T* memory, const T* value) {
object = memory; array_init<T, N>(memory, size, value);
}
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template<typename... Args>
void init(T* memory, Args&&... args) {
array_init_args(memory, size, sp_forward<Args>(args)...);
object = memory;
}
#endif
#endif
void init_list(T* memory, const T* list) {
array_init_list(memory, size, list);
object = memory;
}
template<std::size_t M>
void init_list(T* memory, const T* list) {
array_init_list<T, M>(memory, size, list);
object = memory; object = memory;
} }
void noinit(T* memory) { void noinit(T* memory) {
array_noinit(memory, size); array_noinit(memory, size);
object = memory; object = memory;
} }
void operator()(const void*) { void operator()(const void*) {
if (object) { if (object) {
array_destroy(object, size); array_destroy(object, size);
object = 0; object = 0;
} }
} }
private: private:
std::size_t size; std::size_t size;
T* object; T* object;
}; };
template<typename T, std::size_t N> template<typename T, std::size_t N>
class array_deleter<T[N]> { class array_deleter<T[N]> {
public: public:
array_deleter() array_deleter()
: object(0) { : object(0) {
} }
~array_deleter() { ~array_deleter() {
if (object) { if (object) {
array_destroy(object, N); array_destroy(object, N);
} }
} }
void init(T* memory) { void init(T* memory) {
array_init(memory, N); array_init(memory, N);
object = memory; object = memory;
} }
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
void init(T* memory, T&& value) {
array_init_value(memory, N, sp_forward<T>(value));
object = memory;
}
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template<typename... Args>
void init(T* memory, Args&&... args) {
array_init_args(memory, N, sp_forward<Args>(args)...);
object = memory;
}
#endif
#endif
void init_list(T* memory, const T* list) {
array_init_list(memory, N, list);
object = memory;
}
template<std::size_t M> template<std::size_t M>
void init_list(T* memory, const T* list) { void init(T* memory, const T* value) {
array_init_list<T, M>(memory, N, list); array_init<T, M>(memory, N, value);
object = memory; object = memory;
} }
void noinit(T* memory) { void noinit(T* memory) {
array_noinit(memory, N); array_noinit(memory, N);
object = memory; object = memory;
} }
void operator()(const void*) { void operator()(const void*) {
if (object) { if (object) {
array_destroy(object, N); array_destroy(object, N);
object = 0; object = 0;
} }
} }
private: private:
T* object; T* object;
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -9,40 +9,47 @@
#ifndef BOOST_SMART_PTR_DETAIL_ARRAY_TRAITS_HPP #ifndef BOOST_SMART_PTR_DETAIL_ARRAY_TRAITS_HPP
#define BOOST_SMART_PTR_DETAIL_ARRAY_TRAITS_HPP #define BOOST_SMART_PTR_DETAIL_ARRAY_TRAITS_HPP
#include <boost/type_traits/remove_cv.hpp> #include <cstddef>
namespace boost { namespace boost {
namespace detail { namespace detail {
template<typename T> template<typename T>
struct array_base { struct array_base {
typedef typename boost::remove_cv<T>::type type; typedef T type;
}; };
template<typename T> template<typename T>
struct array_base<T[]> { struct array_base<T[]> {
typedef typename array_base<T>::type type; typedef typename array_base<T>::type type;
}; };
template<typename T, std::size_t N> template<typename T, std::size_t N>
struct array_base<T[N]> { struct array_base<T[N]> {
typedef typename array_base<T>::type type; typedef typename array_base<T>::type type;
}; };
template<typename T> template<typename T>
struct array_total { struct array_total {
enum { enum {
size = 1 size = 1
}; };
}; };
template<typename T, std::size_t N> template<typename T, std::size_t N>
struct array_total<T[N]> { struct array_total<T[N]> {
enum { enum {
size = N * array_total<T>::size size = N * array_total<T>::size
}; };
}; };
template<typename T> template<typename T>
struct array_inner; struct array_inner;
template<typename T> template<typename T>
struct array_inner<T[]> { struct array_inner<T[]> {
typedef T type; typedef T type;
}; };
template<typename T, std::size_t N> template<typename T, std::size_t N>
struct array_inner<T[N]> { struct array_inner<T[N]> {
typedef T type; typedef T type;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -16,27 +16,36 @@
namespace boost { namespace boost {
namespace detail { namespace detail {
template<typename T> template<typename T>
inline void array_destroy(T*, std::size_t, boost::true_type) { inline void array_destroy(T*, std::size_t,
boost::true_type) {
} }
template<typename T> template<typename T>
inline void array_destroy(T* memory, std::size_t size, boost::false_type) { 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_destroy(T* memory, std::size_t size) { inline void array_destroy(T* memory, std::size_t size) {
boost::has_trivial_destructor<T> type; boost::has_trivial_destructor<T> type;
array_destroy(memory, size, type); array_destroy(memory, size, type);
} }
template<typename T> template<typename T>
inline void array_init(T* memory, std::size_t size, boost::true_type) { inline void array_value(T* memory, std::size_t size,
boost::true_type) {
for (std::size_t i = 0; i < size; i++) { for (std::size_t i = 0; i < size; i++) {
memory[i] = T(); void* p1 = memory + i;
::new(p1) T();
} }
} }
template<typename T> template<typename T>
inline void array_init(T* memory, std::size_t size, boost::false_type) { inline void array_value(T* memory, std::size_t size,
boost::false_type) {
#if !defined(BOOST_NO_EXCEPTIONS) #if !defined(BOOST_NO_EXCEPTIONS)
std::size_t i = 0; std::size_t i = 0;
try { try {
@ -55,77 +64,16 @@ namespace boost {
} }
#endif #endif
} }
template<typename T> template<typename T>
inline void array_init(T* memory, std::size_t size) { inline void array_init(T* memory, std::size_t size) {
boost::has_trivial_default_constructor<T> type; boost::has_trivial_default_constructor<T> type;
array_init(memory, size, type); array_value(memory, size, type);
}
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<typename T>
inline void array_init_value(T* memory, std::size_t size, T&& value) {
#if !defined(BOOST_NO_EXCEPTIONS)
std::size_t i = 0;
try {
for (; i < size; i++) {
void* p1 = memory + i;
::new(p1) T(value);
}
} catch (...) {
array_destroy(memory, i);
throw;
}
#else
for (std::size_t i = 0; i < size; i++) {
void* p1 = memory + i;
::new(p1) T(value);
}
#endif
}
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template<typename T, typename... Args>
inline void array_init_args(T* memory, std::size_t size, Args&&... args) {
#if !defined(BOOST_NO_EXCEPTIONS)
std::size_t i = 0;
try {
for (; i < size; i++) {
void* p1 = memory + i;
::new(p1) T(args...);
}
} catch (...) {
array_destroy(memory, i);
throw;
}
#else
for (std::size_t i = 0; i < size; i++) {
void* p1 = memory + i;
::new(p1) T(args...);
}
#endif
}
#endif
#endif
template<typename T>
inline void array_init_list(T* memory, std::size_t size, const T* list) {
#if !defined(BOOST_NO_EXCEPTIONS)
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;
}
#else
for (std::size_t i = 0; i < size; i++) {
void* p1 = memory + i;
::new(p1) T(list[i]);
}
#endif
} }
template<typename T, std::size_t N> template<typename T, std::size_t N>
inline void array_init_list(T* memory, std::size_t size, const T* list) { inline void array_init(T* memory, std::size_t size,
const T* list) {
#if !defined(BOOST_NO_EXCEPTIONS) #if !defined(BOOST_NO_EXCEPTIONS)
std::size_t i = 0; std::size_t i = 0;
try { try {
@ -144,11 +92,15 @@ namespace boost {
} }
#endif #endif
} }
template<typename T> template<typename T>
inline void array_noinit(T*, std::size_t, boost::true_type) { inline void array_default(T*, std::size_t,
boost::true_type) {
} }
template<typename T> template<typename T>
inline void array_noinit(T* memory, std::size_t size, boost::false_type) { inline void array_default(T* memory, std::size_t size,
boost::false_type) {
#if !defined(BOOST_NO_EXCEPTIONS) #if !defined(BOOST_NO_EXCEPTIONS)
std::size_t i = 0; std::size_t i = 0;
try { try {
@ -167,10 +119,11 @@ namespace boost {
} }
#endif #endif
} }
template<typename T> template<typename T>
inline void array_noinit(T* memory, std::size_t size) { inline void array_noinit(T* memory, std::size_t size) {
boost::has_trivial_default_constructor<T> type; boost::has_trivial_default_constructor<T> type;
array_noinit(memory, size, type); array_default(memory, size, type);
} }
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2104 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -15,10 +15,12 @@ namespace boost {
namespace detail { namespace detail {
template<typename T, typename Y = char> template<typename T, typename Y = char>
class make_array_helper; class make_array_helper;
template<typename T, typename Y> template<typename T, typename Y>
class make_array_helper<T[], Y> { class make_array_helper<T[], Y> {
template<typename T2, typename Y2> template<typename T2, typename Y2>
friend class make_array_helper; friend class make_array_helper;
public: public:
typedef Y value_type; typedef Y value_type;
typedef Y* pointer; typedef Y* pointer;
@ -27,28 +29,35 @@ namespace boost {
typedef const Y& const_reference; typedef const Y& const_reference;
typedef std::size_t size_type; typedef std::size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
template<typename U> template<typename U>
struct rebind { struct rebind {
typedef make_array_helper<T[], U> other; typedef make_array_helper<T[], U> other;
}; };
make_array_helper(std::size_t size_, T** data_) make_array_helper(std::size_t size_, T** data_)
: size(sizeof(T) * size_), : size(sizeof(T) * size_),
data(data_) { data(data_) {
} }
template<class U> template<class U>
make_array_helper(const make_array_helper<T[], U>& other) make_array_helper(const make_array_helper<T[], U>& other)
: size(other.size), : size(other.size),
data(other.data) { data(other.data) {
} }
pointer address(reference value) const { pointer address(reference value) const {
return &value; return &value;
} }
const_pointer address(const_reference value) const { const_pointer address(const_reference value) const {
return &value; return &value;
} }
size_type max_size() const { size_type max_size() const {
return static_cast<std::size_t>(-1) / sizeof(Y); return static_cast<std::size_t>(-1) / sizeof(Y);
} }
pointer allocate(size_type count, const void* = 0) { pointer allocate(size_type count, const void* = 0) {
std::size_t a1 = boost::alignment_of<T>::value; std::size_t a1 = boost::alignment_of<T>::value;
std::size_t n1 = count * sizeof(Y) + a1 - 1; std::size_t n1 = count * sizeof(Y) + a1 - 1;
@ -60,33 +69,41 @@ namespace boost {
*data = reinterpret_cast<T*>(p2); *data = reinterpret_cast<T*>(p2);
return reinterpret_cast<Y*>(p1); return reinterpret_cast<Y*>(p1);
} }
void deallocate(pointer memory, size_type) { void deallocate(pointer memory, size_type) {
void* p1 = memory; void* p1 = memory;
::operator delete(p1); ::operator delete(p1);
} }
void construct(pointer memory, const Y& value) { void construct(pointer memory, const Y& value) {
void* p1 = memory; void* p1 = memory;
::new(p1) Y(value); ::new(p1) Y(value);
} }
void destroy(pointer memory) { void destroy(pointer memory) {
memory->~Y(); memory->~Y();
} }
template<typename U> template<typename U>
bool operator==(const make_array_helper<T[], U>&) const { bool operator==(const make_array_helper<T[], U>&) const {
return true; return true;
} }
template<typename U> template<typename U>
bool operator!=(const make_array_helper<T[], U>& other) const { bool operator!=(const make_array_helper<T[], U>& other) const {
return !(*this == other); return !(*this == other);
} }
private: private:
std::size_t size; std::size_t size;
T** data; T** data;
}; };
template<typename T, std::size_t N, typename Y> template<typename T, std::size_t N, typename Y>
class make_array_helper<T[N], Y> { class make_array_helper<T[N], Y> {
template<typename T2, typename Y2> template<typename T2, typename Y2>
friend class make_array_helper; friend class make_array_helper;
public: public:
typedef Y value_type; typedef Y value_type;
typedef Y* pointer; typedef Y* pointer;
@ -95,26 +112,33 @@ namespace boost {
typedef const Y& const_reference; typedef const Y& const_reference;
typedef std::size_t size_type; typedef std::size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
template<typename U> template<typename U>
struct rebind { struct rebind {
typedef make_array_helper<T[N], U> other; typedef make_array_helper<T[N], U> other;
}; };
make_array_helper(T** data_) make_array_helper(T** data_)
: data(data_) { : data(data_) {
} }
template<class U> template<class U>
make_array_helper(const make_array_helper<T[N], U>& other) make_array_helper(const make_array_helper<T[N], U>& other)
: data(other.data) { : data(other.data) {
} }
pointer address(reference value) const { pointer address(reference value) const {
return &value; return &value;
} }
const_pointer address(const_reference value) const { const_pointer address(const_reference value) const {
return &value; return &value;
} }
size_type max_size() const { size_type max_size() const {
return static_cast<std::size_t>(-1) / sizeof(Y); return static_cast<std::size_t>(-1) / sizeof(Y);
} }
pointer allocate(size_type count, const void* = 0) { pointer allocate(size_type count, const void* = 0) {
std::size_t a1 = boost::alignment_of<T>::value; std::size_t a1 = boost::alignment_of<T>::value;
std::size_t n1 = count * sizeof(Y) + a1 - 1; std::size_t n1 = count * sizeof(Y) + a1 - 1;
@ -126,29 +150,36 @@ namespace boost {
*data = reinterpret_cast<T*>(p2); *data = reinterpret_cast<T*>(p2);
return reinterpret_cast<Y*>(p1); return reinterpret_cast<Y*>(p1);
} }
void deallocate(pointer memory, size_type) { void deallocate(pointer memory, size_type) {
void* p1 = memory; void* p1 = memory;
::operator delete(p1); ::operator delete(p1);
} }
void construct(pointer memory, const Y& value) { void construct(pointer memory, const Y& value) {
void* p1 = memory; void* p1 = memory;
::new(p1) Y(value); ::new(p1) Y(value);
} }
void destroy(pointer memory) { void destroy(pointer memory) {
memory->~Y(); memory->~Y();
} }
template<typename U> template<typename U>
bool operator==(const make_array_helper<T[N], U>&) const { bool operator==(const make_array_helper<T[N], U>&) const {
return true; return true;
} }
template<typename U> template<typename U>
bool operator!=(const make_array_helper<T[N], U>& other) const { bool operator!=(const make_array_helper<T[N], U>& other) const {
return !(*this == other); return !(*this == other);
} }
private: private:
enum { enum {
N1 = N * sizeof(T) N1 = N * sizeof(T)
}; };
T** data; T** data;
}; };
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -15,12 +15,15 @@ namespace boost {
namespace detail { namespace detail {
template<typename T> template<typename T>
struct sp_if_array; struct sp_if_array;
template<typename T> template<typename T>
struct sp_if_array<T[]> { struct sp_if_array<T[]> {
typedef boost::shared_ptr<T[]> type; typedef boost::shared_ptr<T[]> type;
}; };
template<typename T> template<typename T>
struct sp_if_size_array; struct sp_if_size_array;
template<typename T, std::size_t N> template<typename T, std::size_t N>
struct sp_if_size_array<T[N]> { struct sp_if_size_array<T[N]> {
typedef boost::shared_ptr<T[N]> type; typedef boost::shared_ptr<T[N]> type;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -9,14 +9,11 @@
#ifndef BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP #ifndef BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP
#define BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP #define BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/detail/array_deleter.hpp> #include <boost/smart_ptr/detail/array_deleter.hpp>
#include <boost/smart_ptr/detail/array_traits.hpp> #include <boost/smart_ptr/detail/array_traits.hpp>
#include <boost/smart_ptr/detail/make_array_helper.hpp> #include <boost/smart_ptr/detail/make_array_helper.hpp>
#include <boost/smart_ptr/detail/sp_if_array.hpp> #include <boost/smart_ptr/detail/sp_if_array.hpp>
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) #include <boost/type_traits/remove_cv.hpp>
#include <initializer_list>
#endif
namespace boost { namespace boost {
template<typename T> template<typename T>
@ -24,219 +21,124 @@ namespace boost {
make_shared(std::size_t size) { make_shared(std::size_t size) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef typename boost::remove_cv<T2>::type T3;
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
std::size_t n1 = size * boost::detail::array_total<T1>::size; std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::make_array_helper<T2[]> a1(n1, &p2); boost::detail::make_array_helper<T3[]> a1(n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1); boost::detail::array_deleter<T3[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2; typedef boost::detail::array_deleter<T3[]>* D2;
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2); d2->init(p2);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<typename T, typename... Args>
inline typename boost::detail::sp_if_array<T>::type
make_shared(std::size_t size, Args&&... args) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::make_array_helper<T2[]> a1(n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2;
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2, boost::detail::sp_forward<Args>(args)...);
return boost::shared_ptr<T>(s1, p1);
}
template<typename T, typename... Args>
inline typename boost::detail::sp_if_size_array<T>::type
make_shared(Args&&... args) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
enum {
N = boost::detail::array_total<T>::size
};
T1* p1 = 0;
T2* p2 = 0;
boost::detail::make_array_helper<T2[N]> a1(&p2);
boost::detail::array_deleter<T2[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2;
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2, boost::detail::sp_forward<Args>(args)...);
return boost::shared_ptr<T>(s1, p1);
}
#endif
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
template<typename T> template<typename T>
inline typename boost::detail::sp_if_size_array<T>::type inline typename boost::detail::sp_if_size_array<T>::type
make_shared(const T& list) { make_shared() {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3; typedef typename boost::remove_cv<T2>::type T3;
enum { enum {
N = boost::detail::array_total<T>::size N = boost::detail::array_total<T>::size
}; };
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
T3* p3 = 0; boost::detail::make_array_helper<T3[N]> a1(&p2);
boost::detail::make_array_helper<T2[N]> a1(&p2); boost::detail::array_deleter<T3[N]> d1;
boost::detail::array_deleter<T2[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2; typedef boost::detail::array_deleter<T3[N]>* D2;
p3 = reinterpret_cast<T3*>(list);
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init_list(p2, p3); d2->init(p2);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
template<typename T> template<typename T>
inline typename boost::detail::sp_if_array<T>::type inline typename boost::detail::sp_if_array<T>::type
make_shared(std::size_t size, make_shared(std::size_t size,
const typename boost::detail::array_inner<T>::type& list) { const typename boost::detail::array_inner<T>::type& value) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3; typedef typename boost::remove_cv<T2>::type T3;
typedef const T2 T4;
enum { enum {
M = boost::detail::array_total<T1>::size M = boost::detail::array_total<T1>::size
}; };
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
T3* p3 = 0; T4* p3 = reinterpret_cast<T4*>(&value);
std::size_t n1 = M * size; std::size_t n1 = M * size;
boost::detail::make_array_helper<T2[]> a1(n1, &p2); boost::detail::make_array_helper<T3[]> a1(n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1); boost::detail::array_deleter<T3[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2; typedef boost::detail::array_deleter<T3[]>* D2;
p3 = reinterpret_cast<T3*>(list);
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->template init_list<M>(p2, p3); d2->template init<M>(p2, p3);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
template<typename T> template<typename T>
inline typename boost::detail::sp_if_size_array<T>::type inline typename boost::detail::sp_if_size_array<T>::type
make_shared(const typename boost::detail::array_inner<T>::type& list) { make_shared(const typename boost::detail::array_inner<T>::type& value) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3; typedef typename boost::remove_cv<T2>::type T3;
typedef const T2 T4;
enum { enum {
M = boost::detail::array_total<T1>::size, M = boost::detail::array_total<T1>::size,
N = boost::detail::array_total<T>::size N = boost::detail::array_total<T>::size
}; };
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
T3* p3 = 0; T4* p3 = reinterpret_cast<T4*>(&value);
boost::detail::make_array_helper<T2[N]> a1(&p2); boost::detail::make_array_helper<T3[N]> a1(&p2);
boost::detail::array_deleter<T2[N]> d1; boost::detail::array_deleter<T3[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2; typedef boost::detail::array_deleter<T3[N]>* D2;
p3 = reinterpret_cast<T3*>(list);
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->template init_list<M>(p2, p3); d2->template init<M>(p2, p3);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
template<typename T>
inline typename boost::detail::sp_if_array<T>::type
make_shared(std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
typedef const T2 T3;
T1* p1 = 0;
T2* p2 = 0;
T3* p3 = 0;
std::size_t n1 = list.size() * boost::detail::array_total<T1>::size;
boost::detail::make_array_helper<T2[]> a1(n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2;
p3 = reinterpret_cast<T3*>(list.begin());
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init_list(p2, p3);
return boost::shared_ptr<T>(s1, p1);
}
#endif
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<typename T>
inline typename boost::detail::sp_if_array<T>::type
make_shared(std::size_t size,
typename boost::detail::array_base<T>::type&& value) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
T1* p1 = 0;
T2* p2 = 0;
std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::make_array_helper<T2[]> a1(n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2;
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2, boost::detail::sp_forward<T2>(value));
return boost::shared_ptr<T>(s1, p1);
}
template<typename T>
inline typename boost::detail::sp_if_size_array<T>::type
make_shared(typename boost::detail::array_base<T>::type&& value) {
typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2;
enum {
N = boost::detail::array_total<T>::size
};
T1* p1 = 0;
T2* p2 = 0;
boost::detail::make_array_helper<T2[N]> a1(&p2);
boost::detail::array_deleter<T2[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2;
p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->init(p2, boost::detail::sp_forward<T2>(value));
return boost::shared_ptr<T>(s1, p1);
}
#endif
#endif
template<typename T> template<typename T>
inline typename boost::detail::sp_if_array<T>::type inline typename boost::detail::sp_if_array<T>::type
make_shared_noinit(std::size_t size) { make_shared_noinit(std::size_t size) {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef typename boost::remove_cv<T2>::type T3;
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
std::size_t n1 = size * boost::detail::array_total<T1>::size; std::size_t n1 = size * boost::detail::array_total<T1>::size;
boost::detail::make_array_helper<T2[]> a1(n1, &p2); boost::detail::make_array_helper<T3[]> a1(n1, &p2);
boost::detail::array_deleter<T2[]> d1(n1); boost::detail::array_deleter<T3[]> d1(n1);
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[]>* D2; typedef boost::detail::array_deleter<T3[]>* D2;
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->noinit(p2); d2->noinit(p2);
return boost::shared_ptr<T>(s1, p1); return boost::shared_ptr<T>(s1, p1);
} }
template<typename T> template<typename T>
inline typename boost::detail::sp_if_size_array<T>::type inline typename boost::detail::sp_if_size_array<T>::type
make_shared_noinit() { make_shared_noinit() {
typedef typename boost::detail::array_inner<T>::type T1; typedef typename boost::detail::array_inner<T>::type T1;
typedef typename boost::detail::array_base<T1>::type T2; typedef typename boost::detail::array_base<T1>::type T2;
typedef typename boost::remove_cv<T2>::type T3;
enum { enum {
N = boost::detail::array_total<T>::size N = boost::detail::array_total<T>::size
}; };
T1* p1 = 0; T1* p1 = 0;
T2* p2 = 0; T3* p2 = 0;
boost::detail::make_array_helper<T2[N]> a1(&p2); boost::detail::make_array_helper<T3[N]> a1(&p2);
boost::detail::array_deleter<T2[N]> d1; boost::detail::array_deleter<T3[N]> d1;
boost::shared_ptr<T> s1(p1, d1, a1); boost::shared_ptr<T> s1(p1, d1, a1);
typedef boost::detail::array_deleter<T2[N]>* D2; typedef boost::detail::array_deleter<T3[N]>* D2;
p1 = reinterpret_cast<T1*>(p2); p1 = reinterpret_cast<T1*>(p2);
D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter()); D2 d2 = static_cast<D2>(s1._internal_get_untyped_deleter());
d2->noinit(p2); d2->noinit(p2);

View File

@ -5,7 +5,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head> </head>
<body text="#000000" bgColor="#ffffff" link="#0000ff" vlink="#0000ff"> <body text="#000000" bgColor="#ffffff" link="#0000ff" vlink="#0000ff">
<h1><IMG height="86" alt="boost.png (6897 bytes)" src="../../boost.png" <h1><img height="86" alt="boost.png (6897 bytes)" src="../../boost.png"
width="277" align="middle" border="0">make_shared and allocate_shared width="277" align="middle" border="0">make_shared and allocate_shared
for arrays</h1> for arrays</h1>
<p><A href="#Introduction">Introduction</A><br> <p><A href="#Introduction">Introduction</A><br>
@ -29,103 +29,69 @@
allowing finer control.</p> allowing finer control.</p>
<h2><a name="Synopsis">Synopsis</a></h2> <h2><a name="Synopsis">Synopsis</a></h2>
<pre>namespace boost { <pre>namespace boost {
template&lt;typename U&gt; // U = T[] template&lt;typename U&gt; // U is T[]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(size_t size); shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(size_t size);
template&lt;typename U, typename A&gt; // U = T[] template&lt;typename U, typename A&gt; // U is T[]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size); shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size);
template&lt;typename U&gt; // U is T[N]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>();
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) &amp;&amp; !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template&lt;typename U, typename A&gt; // U is T[N]
template&lt;typename U, typename... Args&gt; // U = T[] shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator);
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(size_t size, Args&amp;&amp;... args);
template&lt;typename U&gt; // U is T[]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(size_t size, const T&amp; value);
template&lt;typename U, typename... Args&gt; // U = T[N] template&lt;typename U, typename A&gt; // U is T[]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(Args&amp;&amp;... args); shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size, const T&amp; value);
template&lt;typename U, typename A, typename... Args&gt; // U = T[] template&lt;typename U&gt; // U is T[N]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size, Args&amp;&amp;... args); shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(const T&amp; value);
template&lt;typename U, typename A, typename... Args&gt; // U = T[N] template&lt;typename U, typename A&gt; // U is T[N]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, Args&amp;&amp;... args); shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, const T&amp; value);
#endif
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) template&lt;typename U&gt; // U is T[]
template&lt;typename U, typename... Args&gt; // U = T[N]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(const T (&amp;list)[N]);
template&lt;typename U, typename... Args&gt; // U = T[][N]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(size_t size, const T (&amp;list)[N]);
template&lt;typename U, typename... Args&gt; // U = T[M][N]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(const T (&amp;list)[N]);
template&lt;typename U, typename A, typename... Args&gt; // U = T[N]
shared_ptr&lt;T[&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, const T (&amp;list)[N]);
template&lt;typename U, typename A, typename... Args&gt; // U = T[][N]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size, const T (&amp;list)[N]);
template&lt;typename U, typename A, typename... Args&gt; // U = T[M][N]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, const T (&amp;list)[N]);
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
template&lt;typename U, typename... Args&gt; // U = T[]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(initializer_list&lt;T&gt; list);
template&lt;typename U, typename A, typename... Args&gt; // U = T[]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, initializer_list&lt;T&gt; list);
#endif
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template&lt;typename U&gt; // U = T[]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(size_t size, T&amp;&amp; value);
template&lt;typename U&gt; // U = T[N]
shared_ptr&lt;U&gt; <a href="#functions">make_shared</a>(T&amp;&amp; value);
template&lt;typename U, typename A&gt; // U = T[]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, size_t size, T&amp;&amp; value);
template&lt;typename U, typename A&gt; // U = T[N]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared</a>(const A&amp; allocator, T&amp;&amp; value);
#endif
#endif
template&lt;typename U&gt; // U = T[]
shared_ptr&lt;U&gt; <a href="#functions">make_shared_noinit</a>(size_t size); shared_ptr&lt;U&gt; <a href="#functions">make_shared_noinit</a>(size_t size);
template&lt;typename U&gt; // U = T[N] template&lt;typename U, typename A&gt; // U is T[]
shared_ptr&lt;U&gt; <a href="#functions">make_shared_noinit</a>();
template&lt;typename U, typename A&gt; // U = T[]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared_noinit</a>(const A&amp; allocator, size_t size); shared_ptr&lt;U&gt; <a href="#functions">allocate_shared_noinit</a>(const A&amp; allocator, size_t size);
template&lt;typename U, typename A&gt; // U = T[N] template&lt;typename U&gt; // U is T[N]
shared_ptr&lt;U&gt; <a href="#functions">make_shared_noinit</a>();
template&lt;typename U, typename A&gt; // U is T[N]
shared_ptr&lt;U&gt; <a href="#functions">allocate_shared_noinit</a>(const A&amp; allocator); shared_ptr&lt;U&gt; <a href="#functions">allocate_shared_noinit</a>(const A&amp; allocator);
}</pre> }</pre>
<h2><a name="functions">Free Functions</a></h2> <h2><a name="functions">Free Functions</a></h2>
<pre>template&lt;typename U, typename... Args&gt; // U = T[] <pre>template&lt;typename U&gt; // U is T[]
shared_ptr&lt;U&gt; make_shared(size_t size, Args&amp;&amp;... args); shared_ptr&lt;U&gt; make_shared(size_t size);
template&lt;typename U, typename A, typename... Args&gt; // U = T[] template&lt;typename U, typename A&gt; // U is T[]
shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, size_t size, Args&amp;&amp;... args);</pre> shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, size_t size);
template&lt;typename U&gt; // U is T[N]
shared_ptr&lt;U&gt; make_shared();
template&lt;typename U, typename A&gt; // U is T[N]
shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator);</pre>
<blockquote> <blockquote>
<p><b>Requires:</b> The expression <p><b>Requires:</b> The expression
<code>new(pointer) T(forward&lt;Args&gt;(args)...)</code>, where <code>new(pointer) T()</code>, where <code>pointer</code> is a
<code>pointer</code> is a <code>void*</code> pointing to storage <code>void*</code> pointing to storage suitable to hold an object
suitable to hold an object of type <code>T</code>, shall be of type <code>T</code>, shall be well-formed. <code>A</code>
well-formed. <code>A</code> shall be an <em>Allocator</em>, as shall be an <em>Allocator</em>, as described in section 20.1.5
described in section 20.1.5 (<strong>Allocator requirements</strong>) (<strong>Allocator requirements</strong>) of the C++ Standard.
of the C++ Standard. The copy constructor and destructor of The copy constructor and destructor of <code>A</code> shall not
<code>A</code> shall not throw.</p> throw.</p>
<p><b>Effects:</b> Allocates memory suitable for an array of type <p><b>Effects:</b> Allocates memory suitable for an array of type
<code>T</code> and size <code>size</code> and constructs an array <code>T</code> and size <code>size</code> and constructs an array
of objects in it via the placement new expression of objects in it via the placement new expression
<code>new(pointer) T()</code> or <code>new(pointer) T()</code>. <code>allocate_shared</code> uses
<code>new(pointer) T(args...)</code>. a copy of <code>allocator</code> to allocate memory. If an
<code>allocate_shared</code> uses a copy of exception is thrown, has no effect.</p>
<code>allocator</code> to allocate memory. If an exception is thrown,
has no effect.</p>
<p><b>Returns:</b> A <code>shared_ptr</code> instance that stores and <p><b>Returns:</b> A <code>shared_ptr</code> instance that stores and
owns the address of the newly constructed array of type <code>T</code> owns the address of the newly constructed array of type <code>T</code>
and size <code>size</code>.</p> and size <code>size</code>.</p>
@ -137,121 +103,63 @@ shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, size_t size, Args&am
the returned <code>shared_ptr</code> and an array of type the returned <code>shared_ptr</code> and an array of type
<code>T</code> of size <code>size</code> in a single allocation. This <code>T</code> of size <code>size</code> in a single allocation. This
provides efficiency to equivalent to an intrusive smart array provides efficiency to equivalent to an intrusive smart array
pointer.</p> pointer.</p>
<p>The prototypes shown above are used if your compiler supports r-value
references and variadic templates. They perfectly forward the
<code>args</code> parameters to the constructors of
<code>T</code> for each array element.</p>
<p>Otherwise, you can use the overloads which take only the array size
(and the allocator in case of <code>allocate_shared</code>) and do not
take any constructor arguments. These overloads invoke the default
constructor of <code>T</code> for each array element.</p>
</blockquote> </blockquote>
<pre>template&lt;typename U, typename... Args&gt; // U = T[N] <pre>template&lt;typename U&gt; // U is T[]
shared_ptr&lt;U&gt; make_shared(Args&amp;&amp;... args); shared_ptr&lt;U&gt; make_shared(size_t size, const T&amp; value);
template&lt;typename U, typename A, typename... Args&gt; // U = T[N] template&lt;typename U, typename A&gt; // U is T[]
shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, Args&amp;&amp;... args);</pre> shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, size_t size, const T&amp; value);
<blockquote>
<p><b>Description:</b> These overloads of the utilities above are for a
fixed size array.</p>
</blockquote>
<pre>template&lt;typename U, typename... Args&gt; // U = T[]
shared_ptr&lt;U&gt; make_shared(initializer_list&lt;T&gt; list);
template&lt;typename U, typename A, typename... Args&gt; // U = T[] template&lt;typename U&gt; // U is T[N]
shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, initializer_list&lt;T&gt; list);</pre> shared_ptr&lt;U&gt; make_shared(const T&amp; value);
<blockquote>
<p><b>Description:</b> These overloads initialize the array elements
from the initializer list.</p>
</blockquote>
<pre>template&lt;typename U, typename... Args&gt; // U = T[N]
shared_ptr&lt;U&gt; make_shared(const T (&amp;list)[N]);
template&lt;typename U, typename A, typename... Args&gt; // U = T[N] template&lt;typename U, typename A&gt; // U is T[N]
shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, const T (&amp;list)[N]);</pre> shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, const T&amp; value);</pre>
<blockquote>
<p><b>Description:</b> These overloads of the utilities above are for a
fixed size array.</p>
</blockquote>
<pre>template&lt;typename U, typename... Args&gt; // U = T[][N]
shared_ptr&lt;U&gt; make_shared(size_t size, const T (&amp;list)[N]);
template&lt;typename U, typename A, typename... Args&gt; // U = T[][N]
shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, size_t size, const T (&amp;list)[N]);</pre>
<blockquote>
<p><b>Description:</b> These overloads initialize inner array elements
from the initializer list.</p>
</blockquote>
<pre>template&lt;typename U, typename... Args&gt; // U = T[M][N]
shared_ptr&lt;U&gt; make_shared(const T (&amp;list)[N]);
template&lt;typename U, typename A, typename... Args&gt; // U = T[M][N]
shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, const T (&amp;list)[N]);</pre>
<blockquote>
<p><b>Description:</b> These overloads of the utilities above are for a
fixed size array.</p>
</blockquote>
<pre>template&lt;typename U&gt; // U = T[]
shared_ptr&lt;U&gt; make_shared(size_t size, T&amp;&amp; value);
template&lt;typename U, typename A&gt; // U = T[]
shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, size_t size, T&amp;&amp; value);</pre>
<blockquote> <blockquote>
<p><b>Description:</b> These overloads initialize array elements with <p><b>Description:</b> These overloads initialize array elements with
the given value.</p> the given value.</p>
</blockquote> </blockquote>
<pre>template&lt;typename U&gt; // U = T[N] <pre>template&lt;typename U&gt; // U is T[]
shared_ptr&lt;U&gt; make_shared(T&amp;&amp; value);
template&lt;typename U, typename A&gt; // U = T[N]
shared_ptr&lt;U&gt; allocate_shared(const A&amp; allocator, T&amp;&amp; value);</pre>
<blockquote>
<p><b>Description:</b> These overloads of the utilities above are for a
fixed size array.</p>
</blockquote>
<pre>template&lt;typename U&gt; // U = T[]
shared_ptr&lt;U&gt; make_shared_noinit(size_t size); shared_ptr&lt;U&gt; make_shared_noinit(size_t size);
template&lt;typename U, typename A&gt; // U = T[] template&lt;typename U, typename A&gt; // U is T[]
shared_ptr&lt;U&gt; allocate_shared_noinit(const A&amp; allocator, size_t size);</pre> shared_ptr&lt;U&gt; allocate_shared_noinit(const A&amp; allocator, size_t size);
template&lt;typename U&gt; // U is T[N]
shared_ptr&lt;U&gt; make_shared_noinit();
template&lt;typename U, typename A&gt; // U is T[N]
shared_ptr&lt;U&gt; allocate_shared_noinit(const A&amp; allocator);</pre>
<blockquote> <blockquote>
<p><b>Description:</b> These overloads do not perform any value <p><b>Description:</b> These overloads do not perform any value
initialization of elements.</p> initialization of elements.</p>
</blockquote> </blockquote>
<pre>template&lt;typename U&gt; // U = T[N] <h2><a name="example">Examples</a></h2>
shared_ptr&lt;U&gt; make_shared_noinit(); <p>Some examples of each overload of make_shared for arrays:</p>
template&lt;typename U, typename A&gt; // U = T[N]
shared_ptr&lt;U&gt; allocate_shared_noinit(const A&amp; allocator);</pre>
<blockquote>
<p><b>Description:</b> These overloads of the utilities above are for a
fixed size array.</p>
</blockquote>
<h2><a name="example">Example</a></h2>
<p>An example of each overload of make_shared for arrays:</p>
<blockquote> <blockquote>
<pre>boost::shared_ptr&lt;int[]&gt; a1 = boost::make_shared&lt;int[]&gt;(size); <pre>boost::shared_ptr&lt;int[]&gt; a1 = boost::make_shared&lt;int[]&gt;(size);
boost::shared_ptr&lt;point[]&gt; a2 = boost::make_shared&lt;point[]&gt;(size, x, y); boost::shared_ptr&lt;int[8]&gt; a2 = boost::make_shared&lt;int[8]&gt;();
boost::shared_ptr&lt;point[5]&gt; a3 = boost::make_shared&lt;point[5]&gt;(x, y); boost::shared_ptr&lt;int[][2]&gt; a3 = boost::make_shared&lt;int[][2]&gt;(size);
boost::shared_ptr&lt;int[]&gt; a4 = boost::make_shared&lt;int[]&gt;({1, 2, 3}); boost::shared_ptr&lt;int[4][2]&gt; a4 = boost::make_shared&lt;int[4][2]&gt;();
boost::shared_ptr&lt;int[3]&gt; a5 = boost::make_shared&lt;int[3]&gt;({1, 2, 3}); boost::shared_ptr&lt;int[]&gt; a5 = boost::make_shared&lt;int[]&gt;(size, 1);
boost::shared_ptr&lt;int[][3]&gt; a6 = boost::make_shared&lt;int[][3]&gt;(size, {1, 2, 3}); boost::shared_ptr&lt;int[8]&gt; a6 = boost::make_shared&lt;int[8]&gt;(1);
boost::shared_ptr&lt;int[5][3]&gt; a7 = boost::make_shared&lt;int[5][3]&gt;({1, 2, 3}); boost::shared_ptr&lt;int[][2]&gt; a7 = boost::make_shared&lt;int[][2]&gt;(size, {1, 2});
boost::shared_ptr&lt;point[]&gt; a8 = boost::make_shared&lt;point[]&gt;(size, {x, y}); boost::shared_ptr&lt;int[4][2]&gt; a8 = boost::make_shared&lt;int[4][2]&gt;({1, 2});
boost::shared_ptr&lt;point[5]&gt; a9 = boost::make_shared&lt;point[5]&gt;({x, y}); boost::shared_ptr&lt;int[]&gt; a9 = boost::make_shared_noinit&lt;int[]&gt;(size);
boost::shared_ptr&lt;int[]&gt; a10 = boost::make_shared_noinit&lt;int[]&gt;(size); boost::shared_ptr&lt;int[8]&gt; a10 = boost::make_shared_noinit&lt;int[8]&gt;();
boost::shared_ptr&lt;int[5]&gt; a11 = boost::make_shared_noinit&lt;int[5]&gt;();</pre> boost::shared_ptr&lt;int[][2]&gt; a11 = boost::make_shared_noinit&lt;int[][2]&gt;(size);
boost::shared_ptr&lt;int[4][2]&gt; a12 = boost::make_shared_noinit&lt;int[4][2]&gt;();</pre>
</blockquote> </blockquote>
<h2><a name="history">History</a></h2> <h2><a name="history">History</a></h2>
<p>November 2012. Glen Fernandes contributed implementations of <p>November 2012. Glen Fernandes contributed implementations of
make_shared and allocate_shared for arrays.</p> make_shared and allocate_shared for arrays.</p>
<hr> <hr>
<p>$Date: 2012-10-30 10:12:25 -0800 (Tue, 30 Oct 2012) $</p> <p>$Date: 2014-01-20 11:10:00 -0800 (Mon, 20 Jan 2014) $</p>
<p><small>Copyright 2012 Glen Fernandes. Distributed under the Boost <p><small>Copyright 2012-2014 Glen Fernandes. Distributed under the
Software License, Version 1.0. See accompanying file Boost Software License, Version 1.0. See accompanying file
<A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> or copy at <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at
<A href="http://www.boost.org/LICENSE_1_0.txt"> <a href="http://www.boost.org/LICENSE_1_0.txt">
http://www.boost.org/LICENSE_1_0.txt</A>.</small></p> http://www.boost.org/LICENSE_1_0.txt</a>.</small></p>
</body> </body>
</html> </html>

View File

@ -136,22 +136,16 @@ import testing ;
[ compile-fail array_fail_array_access.cpp ] [ compile-fail array_fail_array_access.cpp ]
[ run make_shared_array_test.cpp ] [ run make_shared_array_test.cpp ]
[ run make_shared_arrays_test.cpp ] [ run make_shared_arrays_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ]
[ run make_shared_array_create_test.cpp ]
[ run make_shared_array_init_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ]
[ run make_shared_arrays_create_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ]
[ run make_shared_arrays_init_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ]
[ run make_shared_array_throws_test.cpp ] [ run make_shared_array_throws_test.cpp ]
[ run make_shared_array_esft_test.cpp ] [ run make_shared_array_esft_test.cpp ]
[ run make_shared_array_args_test.cpp ] [ run make_shared_array_noinit_test.cpp ]
[ run make_shared_array_value_test.cpp ]
[ run allocate_shared_array_test.cpp ] [ run allocate_shared_array_test.cpp ]
[ run allocate_shared_arrays_test.cpp ] [ run allocate_shared_arrays_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ]
[ run allocate_shared_array_create_test.cpp ]
[ run allocate_shared_array_init_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ]
[ run allocate_shared_arrays_create_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ]
[ run allocate_shared_arrays_init_test.cpp : : : <toolset>gcc-4.6.3_0x:<cxxflags>-fno-deduce-init-list ]
[ run allocate_shared_array_throws_test.cpp ] [ run allocate_shared_array_throws_test.cpp ]
[ run allocate_shared_array_esft_test.cpp ] [ run allocate_shared_array_esft_test.cpp ]
[ run allocate_shared_array_args_test.cpp ] [ run allocate_shared_array_noinit_test.cpp ]
[ run allocate_shared_array_value_test.cpp ]
; ;
} }

View File

@ -1,173 +0,0 @@
// allocate_shared_array_args_test.cpp
//
// Copyright 2007-2009, 2012 Peter Dimov
//
// 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
#include <boost/detail/lightweight_test.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>
#include <cstddef>
class X
{
private:
X( X const & );
X & operator=( X const & );
void * operator new[]( std::size_t n );
void operator delete[]( void * p );
public:
static int instances;
int v;
explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 )
{
++instances;
}
~X()
{
--instances;
}
};
int X::instances = 0;
int main()
{
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 0 );
BOOST_TEST( px[1].v == 0 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
#if !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1 );
BOOST_TEST( px[1].v == 1 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2 );
BOOST_TEST( px[1].v == 1+2 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3 );
BOOST_TEST( px[1].v == 1+2+3 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4 );
BOOST_TEST( px[1].v == 1+2+3+4 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5 );
BOOST_TEST( px[1].v == 1+2+3+4+5 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5, 6 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5+6 );
BOOST_TEST( px[1].v == 1+2+3+4+5+6 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5, 6, 7 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7 );
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5, 6, 7, 8 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8 );
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::allocate_shared< X[] >( std::allocator<X>(), 2, 1, 2, 3, 4, 5, 6, 7, 8, 9 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8+9 );
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8+9 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
#endif
return boost::report_errors();
}

View File

@ -1,114 +0,0 @@
/*
* 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
class type {
public:
static int instances;
explicit type(int a=0, int b=0, int c=0, int d=0, int e=0, int f=0, int g=0, int h=0, int i=0)
: a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h), i(i) {
instances++;
}
~type() {
instances--;
}
const int a;
const int b;
const int c;
const int d;
const int e;
const int f;
const int g;
const int h;
const int i;
private:
type(const type&);
type& operator=(const type&);
};
int type::instances = 0;
int main() {
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 2, 1, 2, 3, 4, 5, 6, 7, 8, 9);
BOOST_TEST(type::instances == 2);
BOOST_TEST(a1[0].a == 1);
BOOST_TEST(a1[0].d == 4);
BOOST_TEST(a1[1].f == 6);
BOOST_TEST(a1[1].i == 9);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2]> a1 = boost::allocate_shared<type[2]>(std::allocator<type>(), 1, 2, 3, 4, 5, 6, 7, 8, 9);
BOOST_TEST(type::instances == 2);
BOOST_TEST(a1[0].a == 1);
BOOST_TEST(a1[0].d == 4);
BOOST_TEST(a1[1].f == 6);
BOOST_TEST(a1[1].i == 9);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2]> a1 = boost::allocate_shared<type[][2]>(std::allocator<type>(), 2, 1, 2, 3, 4, 5, 6, 7);
BOOST_TEST(type::instances == 4);
BOOST_TEST(a1[0][0].a == 1);
BOOST_TEST(a1[0][1].d == 4);
BOOST_TEST(a1[1][0].f == 6);
BOOST_TEST(a1[1][1].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(std::allocator<type>(), 1, 2, 3, 4, 5, 6, 7);
BOOST_TEST(type::instances == 4);
BOOST_TEST(a1[0][0].a == 1);
BOOST_TEST(a1[0][1].d == 4);
BOOST_TEST(a1[1][0].f == 6);
BOOST_TEST(a1[1][1].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2][2]> a1 = boost::allocate_shared<type[][2][2]>(std::allocator<type>(), 2, 1, 2, 3, 4, 5);
BOOST_TEST(type::instances == 8);
BOOST_TEST(a1[0][0][0].a == 1);
BOOST_TEST(a1[0][1][0].c == 3);
BOOST_TEST(a1[1][0][1].e == 5);
BOOST_TEST(a1[1][1][1].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2][2]> a1 = boost::allocate_shared<type[2][2][2]>(std::allocator<type>(), 1, 2, 3, 4, 5);
BOOST_TEST(type::instances == 8);
BOOST_TEST(a1[0][0][0].a == 1);
BOOST_TEST(a1[0][1][0].c == 3);
BOOST_TEST(a1[1][0][1].e == 5);
BOOST_TEST(a1[1][1][1].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2][2][2]> a1 = boost::allocate_shared<type[][2][2][2]>(std::allocator<type>(), 2, 1, 2, 3);
BOOST_TEST(type::instances == 16);
BOOST_TEST(a1[0][0][0][1].a == 1);
BOOST_TEST(a1[0][0][1][0].c == 3);
BOOST_TEST(a1[0][1][0][0].f == 0);
BOOST_TEST(a1[1][0][0][0].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2][2][2]> a1 = boost::allocate_shared<type[2][2][2][2]>(std::allocator<type>(), 1, 2, 3);
BOOST_TEST(type::instances == 16);
BOOST_TEST(a1[0][0][0][1].a == 1);
BOOST_TEST(a1[0][0][1][0].c == 3);
BOOST_TEST(a1[0][1][0][0].f == 0);
BOOST_TEST(a1[1][0][0][0].i == 0);
}
#endif
return boost::report_errors();
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -14,12 +14,15 @@ class type
: public boost::enable_shared_from_this<type> { : public boost::enable_shared_from_this<type> {
public: public:
static unsigned int instances; static unsigned int instances;
explicit type() { explicit type() {
instances++; instances++;
} }
~type() { ~type() {
instances--; instances--;
} }
private: private:
type(const type&); type(const type&);
type& operator=(const type&); type& operator=(const type&);
@ -38,6 +41,7 @@ int main() {
BOOST_TEST(type::instances == 3); BOOST_TEST(type::instances == 3);
} }
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3); boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
@ -48,5 +52,6 @@ int main() {
BOOST_TEST(type::instances == 3); BOOST_TEST(type::instances == 3);
} }
} }
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -1,84 +0,0 @@
/*
* 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
class type {
public:
type(int value)
: value(value) {
}
const int value;
private:
type& operator=(const type&);
};
int main() {
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
{
boost::shared_ptr<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), { 0, 1, 2, 3 });
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<const int[4]> a1 = boost::allocate_shared<const int[4]>(std::allocator<int>(), { 0, 1, 2, 3 });
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<type[4]> a1 = boost::allocate_shared<type[4]>(std::allocator<type>(), { 0, 1, 2, 3 });
BOOST_TEST(a1[0].value == 0);
BOOST_TEST(a1[1].value == 1);
BOOST_TEST(a1[2].value == 2);
BOOST_TEST(a1[3].value == 3);
}
{
boost::shared_ptr<const type[4]> a1 = boost::allocate_shared<const type[4]>(std::allocator<type>(), { 0, 1, 2, 3 });
BOOST_TEST(a1[0].value == 0);
BOOST_TEST(a1[1].value == 1);
BOOST_TEST(a1[2].value == 2);
BOOST_TEST(a1[3].value == 3);
}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), { 0, 1, 2, 3 });
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), { 0, 1, 2, 3 });
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), { 0, 1, 2, 3 });
BOOST_TEST(a1[0].value == 0);
BOOST_TEST(a1[1].value == 1);
BOOST_TEST(a1[2].value == 2);
BOOST_TEST(a1[3].value == 3);
}
{
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), { 0, 1, 2, 3 });
BOOST_TEST(a1[0].value == 0);
BOOST_TEST(a1[1].value == 1);
BOOST_TEST(a1[2].value == 2);
BOOST_TEST(a1[3].value == 3);
}
#endif
#endif
return boost::report_errors();
}

View File

@ -0,0 +1,181 @@
/*
* Copyright (c) 2012-2014 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
class type {
public:
static unsigned int instances;
explicit type() {
instances++;
}
~type() {
instances--;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned int type::instances = 0;
int main() {
{
boost::shared_ptr<int[]> a1 = boost::allocate_shared_noinit<int[]>(std::allocator<int>(), 3);
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[3]> a1 = boost::allocate_shared_noinit<int[3]>(std::allocator<int>());
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared_noinit<int[][2]>(std::allocator<int>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared_noinit<int[2][2]>(std::allocator<int>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[]> a1 = boost::allocate_shared_noinit<const int[]>(std::allocator<int>(), 3);
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared_noinit<const int[3]>(std::allocator<int>());
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared_noinit<const int[][2]>(std::allocator<int>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared_noinit<const int[2][2]>(std::allocator<int>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[3]> a1 = boost::allocate_shared_noinit<type[3]>(std::allocator<type>());
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2]> a1 = boost::allocate_shared_noinit<type[][2]>(std::allocator<type>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2]> a1 = boost::allocate_shared_noinit<type[2][2]>(std::allocator<type>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[]> a1 = boost::allocate_shared_noinit<const type[]>(std::allocator<type>(), 3);
const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared_noinit<const type[3]>(std::allocator<type>());
const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[][2]> a1 = boost::allocate_shared_noinit<const type[][2]>(std::allocator<type>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[2][2]> a1 = boost::allocate_shared_noinit<const type[2][2]>(std::allocator<type>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@ -1,9 +1,9 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
* Version 1.0. (See accompanying file LICENSE_1_0.txt * Version 1.0. (See accompanying file LICENSE_1_0.txt
* or copy at http://boost.org/LICENSE_1_0.txt) * or copy at http://boost.org/LICENSE_1_0.txt)
*/ */
#include <boost/detail/lightweight_test.hpp> #include <boost/detail/lightweight_test.hpp>
@ -14,17 +14,18 @@
class type { class type {
public: public:
static unsigned int instances; static unsigned int instances;
explicit type(int = 0, int = 0)
: member() { explicit type() {
instances++; instances++;
} }
~type() { ~type() {
instances--; instances--;
} }
private: private:
type(const type&); type(const type&);
type& operator=(const type&); type& operator=(const type&);
double member;
}; };
unsigned int type::instances = 0; unsigned int type::instances = 0;
@ -40,6 +41,38 @@ int main() {
BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0); BOOST_TEST(a1[2] == 0);
} }
{
boost::shared_ptr<int[3]> a1 = boost::allocate_shared<int[3]>(std::allocator<int>());
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
}
{ {
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 3); boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 3);
const int* a2 = a1.get(); const int* a2 = a1.get();
@ -50,6 +83,38 @@ int main() {
BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0); BOOST_TEST(a1[2] == 0);
} }
{
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared<const int[3]>(std::allocator<int>());
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared<const int[][2]>(std::allocator<int>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
}
{
boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared<const int[2][2]>(std::allocator<int>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
}
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3); boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3);
@ -62,6 +127,40 @@ int main() {
a1.reset(); a1.reset();
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(std::allocator<type>());
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2]> a1 = boost::allocate_shared<type[][2]>(std::allocator<type>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(std::allocator<type>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), 3); boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), 3);
@ -73,109 +172,10 @@ int main() {
a1.reset(); a1.reset();
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 3, 1, 5); boost::shared_ptr<const type[3]> a1 = boost::allocate_shared<const type[3]>(std::allocator<type>());
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[3]> a1 = boost::allocate_shared<type[3]>(std::allocator<type>(), 1, 5);
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[]> a1 = boost::allocate_shared<const type[]>(std::allocator<type>(), 3, 1, 5);
const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared<const type[3]>(std::allocator<type>(), 1, 5);
const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset();
BOOST_TEST(type::instances == 0);
}
#endif
{
boost::shared_ptr<int[]> a1 = boost::allocate_shared_noinit<int[]>(std::allocator<int>(), 3);
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[3]> a1 = boost::allocate_shared_noinit<int[3]>(std::allocator<int>());
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[]> a1 = boost::allocate_shared_noinit<const int[]>(std::allocator<int>(), 3);
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[3]> a1 = boost::allocate_shared_noinit<const int[3]>(std::allocator<int>());
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 3);
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[3]> a1 = boost::allocate_shared_noinit<type[3]>(std::allocator<type>());
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[]> a1 = boost::allocate_shared_noinit<const type[]>(std::allocator<type>(), 3);
const type* a2 = a1.get(); const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0); BOOST_TEST(a2 != 0);
@ -184,16 +184,26 @@ int main() {
a1.reset(); a1.reset();
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<const type[3]> a1 = boost::allocate_shared_noinit<const type[3]>(std::allocator<type>()); boost::shared_ptr<const type[][2]> a1 = boost::allocate_shared<const type[][2]>(std::allocator<type>(), 2);
const type* a2 = a1.get(); BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0); BOOST_TEST(type::instances == 4);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset(); a1.reset();
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[2][2]> a1 = boost::allocate_shared<const type[2][2]>(std::allocator<type>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -12,15 +12,18 @@
class type { class type {
public: public:
static unsigned int instances; static unsigned int instances;
explicit type() { explicit type() {
if (instances == 5) { if (instances == 5) {
throw true; throw true;
} }
instances++; instances++;
} }
~type() { ~type() {
instances--; instances--;
} }
private: private:
type(const type&); type(const type&);
type& operator=(const type&); type& operator=(const type&);
@ -36,6 +39,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::allocate_shared<type[][2]>(std::allocator<type>(), 3); boost::allocate_shared<type[][2]>(std::allocator<type>(), 3);
@ -43,7 +47,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::allocate_shared<type[6]>(std::allocator<type>()); boost::allocate_shared<type[6]>(std::allocator<type>());
@ -51,6 +55,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::allocate_shared<type[3][2]>(std::allocator<type>()); boost::allocate_shared<type[3][2]>(std::allocator<type>());
@ -58,7 +63,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
#endif
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 6); boost::allocate_shared_noinit<type[]>(std::allocator<type>(), 6);
@ -66,6 +71,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::allocate_shared_noinit<type[][2]>(std::allocator<type>(), 3); boost::allocate_shared_noinit<type[][2]>(std::allocator<type>(), 3);
@ -73,5 +79,22 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0);
try {
boost::allocate_shared_noinit<type[6]>(std::allocator<type>());
BOOST_ERROR("allocate_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::allocate_shared_noinit<type[3][2]>(std::allocator<type>());
BOOST_ERROR("allocate_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2012-2014 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
int main() {
{
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), 4, 1);
BOOST_TEST(a1[0] == 1);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 1);
BOOST_TEST(a1[3] == 1);
}
{
boost::shared_ptr<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), 1);
BOOST_TEST(a1[0] == 1);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 1);
BOOST_TEST(a1[3] == 1);
}
{
boost::shared_ptr<const int[]> a1 = boost::allocate_shared<const int[]>(std::allocator<int>(), 4, 1);
BOOST_TEST(a1[0] == 1);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 1);
BOOST_TEST(a1[3] == 1);
}
{
boost::shared_ptr<const int[4]> a1 = boost::allocate_shared<const int[4]>(std::allocator<int>(), 1);
BOOST_TEST(a1[0] == 1);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 1);
BOOST_TEST(a1[3] == 1);
}
return boost::report_errors();
}

View File

@ -1,94 +0,0 @@
/*
* 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
class type {
public:
type(int x, int y)
: x(x), y(y) {
}
const int x;
const int y;
private:
type& operator=(const type&);
};
int main() {
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
{
boost::shared_ptr<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), {0, 1, 2, 3});
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[1][0] == 2);
BOOST_TEST(a1[1][1] == 3);
}
{
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2, {0, 1});
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 1);
}
{
boost::shared_ptr<int[][2][2]> a1 = boost::allocate_shared<int[][2][2]>(std::allocator<int>(), 2, { {0, 1}, {2, 3} });
BOOST_TEST(a1[0][0][0] == 0);
BOOST_TEST(a1[0][0][1] == 1);
BOOST_TEST(a1[1][1][0] == 2);
BOOST_TEST(a1[1][1][1] == 3);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>(), {0, 1});
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 1);
}
{
boost::shared_ptr<int[2][2][2]> a1 = boost::allocate_shared<int[2][2][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
BOOST_TEST(a1[0][0][0] == 0);
BOOST_TEST(a1[0][0][1] == 1);
BOOST_TEST(a1[1][1][0] == 2);
BOOST_TEST(a1[1][1][1] == 3);
}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(std::allocator<int>(), {0, 1, 2, 3});
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
#endif
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
{
boost::shared_ptr<type[]> a1 = boost::allocate_shared<type[]>(std::allocator<type>(), 4, {1, 2});
BOOST_TEST(a1[0].x == 1);
BOOST_TEST(a1[1].y == 2);
BOOST_TEST(a1[2].x == 1);
BOOST_TEST(a1[3].y == 2);
}
{
boost::shared_ptr<type[4]> a1 = boost::allocate_shared<type[4]>(std::allocator<type>(), {1, 2});
BOOST_TEST(a1[0].x == 1);
BOOST_TEST(a1[1].y == 2);
BOOST_TEST(a1[2].x == 1);
BOOST_TEST(a1[3].y == 2);
}
#endif
#endif
return boost::report_errors();
}

View File

@ -1,23 +0,0 @@
/*
* 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp>
int main() {
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[1][0] == 2);
BOOST_TEST(a1[1][1] == 3);
}
#endif
return boost::report_errors();
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -9,152 +9,40 @@
#include <boost/detail/lightweight_test.hpp> #include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/allocate_shared_array.hpp> #include <boost/smart_ptr/allocate_shared_array.hpp>
class type {
public:
static unsigned int instances;
explicit type(int = 0, int = 0)
: member() {
instances++;
}
~type() {
instances--;
}
private:
type(const type&);
type& operator=(const type&);
double member;
};
unsigned int type::instances = 0;
int main() { int main() {
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
{ {
boost::shared_ptr<int[][2][2]> a1 = boost::allocate_shared<int[][2][2]>(std::allocator<int>(), 2); boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), 2, {0, 1});
BOOST_TEST(a1.get() != 0); BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[0][0][1] == 0); BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[0][1][0] == 0); BOOST_TEST(a1[1][1] == 1);
BOOST_TEST(a1[1][0][0] == 0);
} }
{ {
boost::shared_ptr<const int[][2][2]> a1 = boost::allocate_shared<const int[][2][2]>(std::allocator<int>(), 2); boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>(), { 0, 1 });
BOOST_TEST(a1.get() != 0); BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[0][0][1] == 0); BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[0][1][0] == 0); BOOST_TEST(a1[1][1] == 1);
BOOST_TEST(a1[1][0][0] == 0);
} }
BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<type[][2][2]> a1 = boost::allocate_shared<type[][2][2]>(std::allocator<type>(), 2); boost::shared_ptr<const int[][2]> a1 = boost::allocate_shared<const int[][2]>(std::allocator<int>(), 2, { 0, 1 });
BOOST_TEST(a1.get() != 0); BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(type::instances == 8); BOOST_TEST(a1[1][0] == 0);
a1.reset(); BOOST_TEST(a1[1][1] == 1);
BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<const type[][2][2]> a1 = boost::allocate_shared<const type[][2][2]>(std::allocator<type>(), 2); boost::shared_ptr<const int[2][2]> a1 = boost::allocate_shared<const int[2][2]>(std::allocator<int>(), { 0, 1 });
BOOST_TEST(a1.get() != 0); BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(type::instances == 8); BOOST_TEST(a1[1][0] == 0);
a1.reset(); BOOST_TEST(a1[1][1] == 1);
BOOST_TEST(type::instances == 0);
}
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2][2]> a1 = boost::allocate_shared<type[][2][2]>(std::allocator<type>(), 2, 1, 5);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2][2]> a1 = boost::allocate_shared<type[2][2][2]>(std::allocator<type>(), 1, 5);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[][2][2]> a1 = boost::allocate_shared<const type[][2][2]>(std::allocator<type>(), 2, 1, 5);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[2][2][2]> a1 = boost::allocate_shared<const type[2][2][2]>(std::allocator<type>(), 1, 5);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
} }
#endif #endif
{
boost::shared_ptr<int[][2][2]> a1 = boost::allocate_shared_noinit<int[][2][2]>(std::allocator<int>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<int[2][2][2]> a1 = boost::allocate_shared_noinit<int[2][2][2]>(std::allocator<int>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[][2][2]> a1 = boost::allocate_shared_noinit<const int[][2][2]>(std::allocator<int>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[2][2][2]> a1 = boost::allocate_shared_noinit<const int[2][2][2]>(std::allocator<int>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2][2]> a1 = boost::allocate_shared_noinit<type[][2][2]>(std::allocator<type>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2][2]> a1 = boost::allocate_shared_noinit<type[2][2][2]>(std::allocator<type>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[][2][2]> a1 = boost::allocate_shared_noinit<const type[][2][2]>(std::allocator<type>(), 2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[2][2][2]> a1 = boost::allocate_shared_noinit<const type[2][2][2]>(std::allocator<type>());
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -1,172 +0,0 @@
// make_shared_array_args_test.cpp
//
// Copyright 2007-2009, 2012 Peter Dimov
//
// 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
#include <boost/detail/lightweight_test.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <cstddef>
class X
{
private:
X( X const & );
X & operator=( X const & );
void * operator new[]( std::size_t n );
void operator delete[]( void * p );
public:
static int instances;
int v;
explicit X( int a1 = 0, int a2 = 0, int a3 = 0, int a4 = 0, int a5 = 0, int a6 = 0, int a7 = 0, int a8 = 0, int a9 = 0 ): v( a1+a2+a3+a4+a5+a6+a7+a8+a9 )
{
++instances;
}
~X()
{
--instances;
}
};
int X::instances = 0;
int main()
{
BOOST_TEST( X::instances == 0 );
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 0 );
BOOST_TEST( px[1].v == 0 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
#if !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES )
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1 );
BOOST_TEST( px[1].v == 1 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2 );
BOOST_TEST( px[1].v == 1+2 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3 );
BOOST_TEST( px[1].v == 1+2+3 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4 );
BOOST_TEST( px[1].v == 1+2+3+4 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5 );
BOOST_TEST( px[1].v == 1+2+3+4+5 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5+6 );
BOOST_TEST( px[1].v == 1+2+3+4+5+6 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6, 7 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7 );
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6, 7, 8 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8 );
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
{
boost::shared_ptr< X[] > px = boost::make_shared< X[] >( 2, 1, 2, 3, 4, 5, 6, 7, 8, 9 );
BOOST_TEST( X::instances == 2 );
BOOST_TEST( px[0].v == 1+2+3+4+5+6+7+8+9 );
BOOST_TEST( px[1].v == 1+2+3+4+5+6+7+8+9 );
px.reset();
BOOST_TEST( X::instances == 0 );
}
#endif
return boost::report_errors();
}

View File

@ -1,114 +0,0 @@
/*
* 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
class type {
public:
static int instances;
explicit type(int a=0, int b=0, int c=0, int d=0, int e=0, int f=0, int g=0, int h=0, int i=0)
: a(a), b(b), c(c), d(d), e(e), f(f), g(g), h(h), i(i) {
instances++;
}
~type() {
instances--;
}
const int a;
const int b;
const int c;
const int d;
const int e;
const int f;
const int g;
const int h;
const int i;
private:
type(const type&);
type& operator=(const type&);
};
int type::instances = 0;
int main() {
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(2, 1, 2, 3, 4, 5, 6, 7, 8, 9);
BOOST_TEST(type::instances == 2);
BOOST_TEST(a1[0].a == 1);
BOOST_TEST(a1[0].d == 4);
BOOST_TEST(a1[1].f == 6);
BOOST_TEST(a1[1].i == 9);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2]> a1 = boost::make_shared<type[2]>(1, 2, 3, 4, 5, 6, 7, 8, 9);
BOOST_TEST(type::instances == 2);
BOOST_TEST(a1[0].a == 1);
BOOST_TEST(a1[0].d == 4);
BOOST_TEST(a1[1].f == 6);
BOOST_TEST(a1[1].i == 9);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2]> a1 = boost::make_shared<type[][2]>(2, 1, 2, 3, 4, 5, 6, 7);
BOOST_TEST(type::instances == 4);
BOOST_TEST(a1[0][0].a == 1);
BOOST_TEST(a1[0][1].d == 4);
BOOST_TEST(a1[1][0].f == 6);
BOOST_TEST(a1[1][1].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2]> a1 = boost::make_shared<type[2][2]>(1, 2, 3, 4, 5, 6, 7);
BOOST_TEST(type::instances == 4);
BOOST_TEST(a1[0][0].a == 1);
BOOST_TEST(a1[0][1].d == 4);
BOOST_TEST(a1[1][0].f == 6);
BOOST_TEST(a1[1][1].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2][2]> a1 = boost::make_shared<type[][2][2]>(2, 1, 2, 3, 4, 5);
BOOST_TEST(type::instances == 8);
BOOST_TEST(a1[0][0][0].a == 1);
BOOST_TEST(a1[0][1][0].c == 3);
BOOST_TEST(a1[1][0][1].e == 5);
BOOST_TEST(a1[1][1][1].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2][2]> a1 = boost::make_shared<type[2][2][2]>(1, 2, 3, 4, 5);
BOOST_TEST(type::instances == 8);
BOOST_TEST(a1[0][0][0].a == 1);
BOOST_TEST(a1[0][1][0].c == 3);
BOOST_TEST(a1[1][0][1].e == 5);
BOOST_TEST(a1[1][1][1].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2][2][2]> a1 = boost::make_shared<type[][2][2][2]>(2, 1, 2, 3);
BOOST_TEST(type::instances == 16);
BOOST_TEST(a1[0][0][0][1].a == 1);
BOOST_TEST(a1[0][0][1][0].c == 3);
BOOST_TEST(a1[0][1][0][0].f == 0);
BOOST_TEST(a1[1][0][0][0].i == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2][2][2]> a1 = boost::make_shared<type[2][2][2][2]>(1, 2, 3);
BOOST_TEST(type::instances == 16);
BOOST_TEST(a1[0][0][0][1].a == 1);
BOOST_TEST(a1[0][0][1][0].c == 3);
BOOST_TEST(a1[0][1][0][0].f == 0);
BOOST_TEST(a1[1][0][0][0].i == 0);
}
#endif
return boost::report_errors();
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -14,12 +14,15 @@ class type
: public boost::enable_shared_from_this<type> { : public boost::enable_shared_from_this<type> {
public: public:
static unsigned int instances; static unsigned int instances;
explicit type() { explicit type() {
instances++; instances++;
} }
~type() { ~type() {
instances--; instances--;
} }
private: private:
type(const type&); type(const type&);
type& operator=(const type&); type& operator=(const type&);
@ -38,6 +41,7 @@ int main() {
BOOST_TEST(type::instances == 3); BOOST_TEST(type::instances == 3);
} }
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3); boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
@ -48,5 +52,6 @@ int main() {
BOOST_TEST(type::instances == 3); BOOST_TEST(type::instances == 3);
} }
} }
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -1,84 +0,0 @@
/*
* 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
class type {
public:
type(int value)
: value(value) {
}
const int value;
private:
type& operator=(const type&);
};
int main() {
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
{
boost::shared_ptr<int[4]> a1 = boost::make_shared<int[4]>({ 0, 1, 2, 3 });
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<const int[4]> a1 = boost::make_shared<const int[4]>({ 0, 1, 2, 3 });
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<type[4]> a1 = boost::make_shared<type[4]>({ 0, 1, 2, 3 });
BOOST_TEST(a1[0].value == 0);
BOOST_TEST(a1[1].value == 1);
BOOST_TEST(a1[2].value == 2);
BOOST_TEST(a1[3].value == 3);
}
{
boost::shared_ptr<const type[4]> a1 = boost::make_shared<const type[4]>({ 0, 1, 2, 3 });
BOOST_TEST(a1[0].value == 0);
BOOST_TEST(a1[1].value == 1);
BOOST_TEST(a1[2].value == 2);
BOOST_TEST(a1[3].value == 3);
}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>({ 0, 1, 2, 3 });
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>({ 0, 1, 2, 3 });
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>({ 0, 1, 2, 3 });
BOOST_TEST(a1[0].value == 0);
BOOST_TEST(a1[1].value == 1);
BOOST_TEST(a1[2].value == 2);
BOOST_TEST(a1[3].value == 3);
}
{
boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>({ 0, 1, 2, 3 });
BOOST_TEST(a1[0].value == 0);
BOOST_TEST(a1[1].value == 1);
BOOST_TEST(a1[2].value == 2);
BOOST_TEST(a1[3].value == 3);
}
#endif
#endif
return boost::report_errors();
}

View File

@ -0,0 +1,181 @@
/*
* Copyright (c) 2012-2014 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
#include <boost/smart_ptr/weak_ptr.hpp>
#include <boost/type_traits/alignment_of.hpp>
class type {
public:
static unsigned int instances;
explicit type() {
instances++;
}
~type() {
instances--;
}
private:
type(const type&);
type& operator=(const type&);
};
unsigned int type::instances = 0;
int main() {
{
boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(3);
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[3]> a1 = boost::make_shared_noinit<int[3]>();
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[][2]> a1 = boost::make_shared_noinit<int[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::make_shared_noinit<int[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[]> a1 = boost::make_shared_noinit<const int[]>(3);
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[3]> a1 = boost::make_shared_noinit<const int[3]>();
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[][2]> a1 = boost::make_shared_noinit<const int[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared_noinit<const int[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[3]> a1 = boost::make_shared_noinit<type[3]>();
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2]> a1 = boost::make_shared_noinit<type[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2]> a1 = boost::make_shared_noinit<type[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[]> a1 = boost::make_shared_noinit<const type[]>(3);
const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[3]> a1 = boost::make_shared_noinit<const type[3]>();
const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[][2]> a1 = boost::make_shared_noinit<const type[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[2][2]> a1 = boost::make_shared_noinit<const type[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors();
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -14,17 +14,18 @@
class type { class type {
public: public:
static unsigned int instances; static unsigned int instances;
explicit type(int = 0, int = 0)
: member() { explicit type() {
instances++; instances++;
} }
~type() { ~type() {
instances--; instances--;
} }
private: private:
type(const type&); type(const type&);
type& operator=(const type&); type& operator=(const type&);
double member;
}; };
unsigned int type::instances = 0; unsigned int type::instances = 0;
@ -40,6 +41,38 @@ int main() {
BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0); BOOST_TEST(a1[2] == 0);
} }
{
boost::shared_ptr<int[3]> a1 = boost::make_shared<int[3]>();
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
}
{ {
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(3); boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(3);
const int* a2 = a1.get(); const int* a2 = a1.get();
@ -50,6 +83,38 @@ int main() {
BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0); BOOST_TEST(a1[2] == 0);
} }
{
boost::shared_ptr<const int[3]> a1 = boost::make_shared<const int[3]>();
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 0);
BOOST_TEST(a1[2] == 0);
}
{
boost::shared_ptr<const int[][2]> a1 = boost::make_shared<const int[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
}
{
boost::shared_ptr<const int[2][2]> a1 = boost::make_shared<const int[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 0);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 0);
}
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3); boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3);
@ -62,6 +127,40 @@ int main() {
a1.reset(); a1.reset();
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[3]> a1 = boost::make_shared<type[3]>();
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2]> a1 = boost::make_shared<type[][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2]> a1 = boost::make_shared<type[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>(3); boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>(3);
@ -73,109 +172,10 @@ int main() {
a1.reset(); a1.reset();
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(3, 1, 5); boost::shared_ptr<const type[3]> a1 = boost::make_shared<const type[3]>();
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[3]> a1 = boost::make_shared<type[3]>(1, 5);
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[]> a1 = boost::make_shared<const type[]>(3, 1, 5);
const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[3]> a1 = boost::make_shared<const type[3]>(1, 5);
const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset();
BOOST_TEST(type::instances == 0);
}
#endif
{
boost::shared_ptr<int[]> a1 = boost::make_shared_noinit<int[]>(3);
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<int[3]> a1 = boost::make_shared_noinit<int[3]>();
int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[]> a1 = boost::make_shared_noinit<const int[]>(3);
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
{
boost::shared_ptr<const int[3]> a1 = boost::make_shared_noinit<const int[3]>();
const int* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<int>::value == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[]> a1 = boost::make_shared_noinit<type[]>(3);
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[3]> a1 = boost::make_shared_noinit<type[3]>();
type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
boost::weak_ptr<type[3]> w1 = a1;
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[]> a1 = boost::make_shared_noinit<const type[]>(3);
const type* a2 = a1.get(); const type* a2 = a1.get();
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0); BOOST_TEST(a2 != 0);
@ -184,16 +184,26 @@ int main() {
a1.reset(); a1.reset();
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<const type[3]> a1 = boost::make_shared_noinit<const type[3]>(); boost::shared_ptr<const type[][2]> a1 = boost::make_shared<const type[][2]>(2);
const type* a2 = a1.get(); BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a2 != 0); BOOST_TEST(type::instances == 4);
BOOST_TEST(size_t(a2) % boost::alignment_of<type>::value == 0);
BOOST_TEST(type::instances == 3);
a1.reset(); a1.reset();
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[2][2]> a1 = boost::make_shared<const type[2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 4);
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -12,15 +12,18 @@
class type { class type {
public: public:
static unsigned int instances; static unsigned int instances;
explicit type() { explicit type() {
if (instances == 5) { if (instances == 5) {
throw true; throw true;
} }
instances++; instances++;
} }
~type() { ~type() {
instances--; instances--;
} }
private: private:
type(const type&); type(const type&);
type& operator=(const type&); type& operator=(const type&);
@ -36,6 +39,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::make_shared<type[][2]>(3); boost::make_shared<type[][2]>(3);
@ -43,7 +47,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::make_shared<type[6]>(); boost::make_shared<type[6]>();
@ -51,6 +55,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::make_shared<type[3][2]>(); boost::make_shared<type[3][2]>();
@ -58,7 +63,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
#endif
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::make_shared_noinit<type[]>(6); boost::make_shared_noinit<type[]>(6);
@ -66,6 +71,7 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
try { try {
boost::make_shared_noinit<type[][2]>(3); boost::make_shared_noinit<type[][2]>(3);
@ -73,5 +79,22 @@ int main() {
} catch (...) { } catch (...) {
BOOST_TEST(type::instances == 0); BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0);
try {
boost::make_shared_noinit<type[6]>();
BOOST_ERROR("make_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
try {
boost::make_shared_noinit<type[3][2]>();
BOOST_ERROR("make_shared_noinit did not throw");
} catch (...) {
BOOST_TEST(type::instances == 0);
}
return boost::report_errors(); return boost::report_errors();
} }

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2012-2014 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
int main() {
{
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(4, 1);
BOOST_TEST(a1[0] == 1);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 1);
BOOST_TEST(a1[3] == 1);
}
{
boost::shared_ptr<int[4]> a1 = boost::make_shared<int[4]>(1);
BOOST_TEST(a1[0] == 1);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 1);
BOOST_TEST(a1[3] == 1);
}
{
boost::shared_ptr<const int[]> a1 = boost::make_shared<const int[]>(4, 1);
BOOST_TEST(a1[0] == 1);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 1);
BOOST_TEST(a1[3] == 1);
}
{
boost::shared_ptr<const int[4]> a1 = boost::make_shared<const int[4]>(1);
BOOST_TEST(a1[0] == 1);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 1);
BOOST_TEST(a1[3] == 1);
}
return boost::report_errors();
}

View File

@ -1,94 +0,0 @@
/*
* 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
class type {
public:
type(int x, int y)
: x(x), y(y) {
}
const int x;
const int y;
private:
type& operator=(const type&);
};
int main() {
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
{
boost::shared_ptr<int[4]> a1 = boost::make_shared<int[4]>({0, 1, 2, 3});
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>({ {0, 1}, {2, 3} });
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[1][0] == 2);
BOOST_TEST(a1[1][1] == 3);
}
{
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2, {0, 1});
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 1);
}
{
boost::shared_ptr<int[][2][2]> a1 = boost::make_shared<int[][2][2]>(2, { {0, 1}, {2, 3} });
BOOST_TEST(a1[0][0][0] == 0);
BOOST_TEST(a1[0][0][1] == 1);
BOOST_TEST(a1[1][1][0] == 2);
BOOST_TEST(a1[1][1][1] == 3);
}
{
boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>({ 0, 1 });
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[1][1] == 1);
}
{
boost::shared_ptr<int[2][2][2]> a1 = boost::make_shared<int[2][2][2]>({ {0, 1}, {2, 3} });
BOOST_TEST(a1[0][0][0] == 0);
BOOST_TEST(a1[0][0][1] == 1);
BOOST_TEST(a1[1][1][0] == 2);
BOOST_TEST(a1[1][1][1] == 3);
}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>({0, 1, 2, 3});
BOOST_TEST(a1[0] == 0);
BOOST_TEST(a1[1] == 1);
BOOST_TEST(a1[2] == 2);
BOOST_TEST(a1[3] == 3);
}
#endif
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
{
boost::shared_ptr<type[]> a1 = boost::make_shared<type[]>(4, {1, 2});
BOOST_TEST(a1[0].x == 1);
BOOST_TEST(a1[1].y == 2);
BOOST_TEST(a1[2].x == 1);
BOOST_TEST(a1[3].y == 2);
}
{
boost::shared_ptr<type[4]> a1 = boost::make_shared<type[4]>({1, 2});
BOOST_TEST(a1[0].x == 1);
BOOST_TEST(a1[1].y == 2);
BOOST_TEST(a1[2].x == 1);
BOOST_TEST(a1[3].y == 2);
}
#endif
#endif
return boost::report_errors();
}

View File

@ -1,23 +0,0 @@
/*
* 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)
*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp>
int main() {
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
{
boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>({ {0, 1}, {2, 3} });
BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[1][0] == 2);
BOOST_TEST(a1[1][1] == 3);
}
#endif
return boost::report_errors();
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012 Glen Joseph Fernandes * Copyright (c) 2012-2014 Glen Joseph Fernandes
* glenfe at live dot com * glenfe at live dot com
* *
* Distributed under the Boost Software License, * Distributed under the Boost Software License,
@ -9,152 +9,40 @@
#include <boost/detail/lightweight_test.hpp> #include <boost/detail/lightweight_test.hpp>
#include <boost/smart_ptr/make_shared_array.hpp> #include <boost/smart_ptr/make_shared_array.hpp>
class type {
public:
static unsigned int instances;
explicit type(int = 0, int = 0)
: member() {
instances++;
}
~type() {
instances--;
}
private:
type(const type&);
type& operator=(const type&);
double member;
};
unsigned int type::instances = 0;
int main() { int main() {
#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
{ {
boost::shared_ptr<int[][2][2]> a1 = boost::make_shared<int[][2][2]>(2); boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>(2, {0, 1});
BOOST_TEST(a1.get() != 0); BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(a1[0][0][1] == 0); BOOST_TEST(a1[1][0] == 0);
BOOST_TEST(a1[0][1][0] == 0); BOOST_TEST(a1[1][1] == 1);
BOOST_TEST(a1[1][0][0] == 0);
}
{
boost::shared_ptr<const int[][2][2]> a1 = boost::make_shared<const int[][2][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(a1[0][0][1] == 0);
BOOST_TEST(a1[0][1][0] == 0);
BOOST_TEST(a1[1][0][0] == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2][2]> a1 = boost::make_shared<type[][2][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[][2][2]> a1 = boost::make_shared<const type[][2][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
} }
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<type[][2][2]> a1 = boost::make_shared<type[][2][2]>(2, 1, 5); boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>({ 0, 1 });
BOOST_TEST(a1.get() != 0); BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(type::instances == 8); BOOST_TEST(a1[1][0] == 0);
a1.reset(); BOOST_TEST(a1[1][1] == 1);
BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<type[2][2][2]> a1 = boost::make_shared<type[2][2][2]>(1, 5); boost::shared_ptr<const int[][2]> a1 = boost::make_shared<const int[][2]>(2, { 0, 1 });
BOOST_TEST(a1.get() != 0); BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(type::instances == 8); BOOST_TEST(a1[1][0] == 0);
a1.reset(); BOOST_TEST(a1[1][1] == 1);
BOOST_TEST(type::instances == 0);
} }
BOOST_TEST(type::instances == 0);
{ {
boost::shared_ptr<const type[][2][2]> a1 = boost::make_shared<const type[][2][2]>(2, 1, 5); boost::shared_ptr<const int[2][2]> a1 = boost::make_shared<const int[2][2]>({ 0, 1 });
BOOST_TEST(a1.get() != 0); BOOST_TEST(a1[0][0] == 0);
BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1[0][1] == 1);
BOOST_TEST(type::instances == 8); BOOST_TEST(a1[1][0] == 0);
a1.reset(); BOOST_TEST(a1[1][1] == 1);
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[2][2][2]> a1 = boost::make_shared<const type[2][2][2]>(1, 5);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
} }
#endif #endif
{
boost::shared_ptr<int[][2][2]> a1 = boost::make_shared_noinit<int[][2][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<int[2][2][2]> a1 = boost::make_shared_noinit<int[2][2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[][2][2]> a1 = boost::make_shared_noinit<const int[][2][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
{
boost::shared_ptr<const int[2][2][2]> a1 = boost::make_shared_noinit<const int[2][2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[][2][2]> a1 = boost::make_shared_noinit<type[][2][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<type[2][2][2]> a1 = boost::make_shared_noinit<type[2][2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[][2][2]> a1 = boost::make_shared_noinit<const type[][2][2]>(2);
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
BOOST_TEST(type::instances == 0);
{
boost::shared_ptr<const type[2][2][2]> a1 = boost::make_shared_noinit<const type[2][2][2]>();
BOOST_TEST(a1.get() != 0);
BOOST_TEST(a1.use_count() == 1);
BOOST_TEST(type::instances == 8);
a1.reset();
BOOST_TEST(type::instances == 0);
}
return boost::report_errors(); return boost::report_errors();
} }