From f837c7f56cbe29dad1e61182e4de4c24ef44b7f3 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 11 Feb 2014 01:29:02 +0200 Subject: [PATCH] Revert "Merge from branch 'develop' into 'master'" This reverts commit 83b3b703e0e728c6e911c9a04cc337656bae7b8f. --- .../boost/smart_ptr/allocate_shared_array.hpp | 202 ++++++++++---- .../detail/allocate_array_helper.hpp | 35 +-- .../boost/smart_ptr/detail/array_deleter.hpp | 64 +++-- .../boost/smart_ptr/detail/array_traits.hpp | 13 +- .../boost/smart_ptr/detail/array_utility.hpp | 103 +++++-- .../smart_ptr/detail/make_array_helper.hpp | 33 +-- .../boost/smart_ptr/detail/sp_if_array.hpp | 5 +- include/boost/smart_ptr/make_shared_array.hpp | 196 ++++++++++---- make_shared_array.html | 254 ++++++++++++------ test/Jamfile.v2 | 18 +- test/allocate_shared_array_args_test.cpp | 173 ++++++++++++ test/allocate_shared_array_create_test.cpp | 114 ++++++++ test/allocate_shared_array_esft_test.cpp | 7 +- test/allocate_shared_array_init_test.cpp | 84 ++++++ test/allocate_shared_array_noinit_test.cpp | 181 ------------- test/allocate_shared_array_test.cpp | 234 ++++++++-------- test/allocate_shared_array_throws_test.cpp | 29 +- test/allocate_shared_array_value_test.cpp | 46 ---- test/allocate_shared_arrays_create_test.cpp | 94 +++++++ test/allocate_shared_arrays_init_test.cpp | 23 ++ test/allocate_shared_arrays_test.cpp | 164 +++++++++-- test/make_shared_array_args_test.cpp | 172 ++++++++++++ test/make_shared_array_create_test.cpp | 114 ++++++++ test/make_shared_array_esft_test.cpp | 7 +- test/make_shared_array_init_test.cpp | 84 ++++++ test/make_shared_array_noinit_test.cpp | 181 ------------- test/make_shared_array_test.cpp | 230 ++++++++-------- test/make_shared_array_throws_test.cpp | 29 +- test/make_shared_array_value_test.cpp | 46 ---- test/make_shared_arrays_create_test.cpp | 94 +++++++ test/make_shared_arrays_init_test.cpp | 23 ++ test/make_shared_arrays_test.cpp | 164 +++++++++-- 32 files changed, 2087 insertions(+), 1129 deletions(-) create mode 100644 test/allocate_shared_array_args_test.cpp create mode 100644 test/allocate_shared_array_create_test.cpp create mode 100644 test/allocate_shared_array_init_test.cpp delete mode 100644 test/allocate_shared_array_noinit_test.cpp delete mode 100644 test/allocate_shared_array_value_test.cpp create mode 100644 test/allocate_shared_arrays_create_test.cpp create mode 100644 test/allocate_shared_arrays_init_test.cpp create mode 100644 test/make_shared_array_args_test.cpp create mode 100644 test/make_shared_array_create_test.cpp create mode 100644 test/make_shared_array_init_test.cpp delete mode 100644 test/make_shared_array_noinit_test.cpp delete mode 100644 test/make_shared_array_value_test.cpp create mode 100644 test/make_shared_arrays_create_test.cpp create mode 100644 test/make_shared_arrays_init_test.cpp diff --git a/include/boost/smart_ptr/allocate_shared_array.hpp b/include/boost/smart_ptr/allocate_shared_array.hpp index 905d311..3ee1655 100644 --- a/include/boost/smart_ptr/allocate_shared_array.hpp +++ b/include/boost/smart_ptr/allocate_shared_array.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -9,11 +9,14 @@ #ifndef BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP #define BOOST_SMART_PTR_ALLOCATE_SHARED_ARRAY_HPP +#include #include #include #include #include -#include +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) +#include +#endif namespace boost { template @@ -21,125 +24,222 @@ namespace boost { allocate_shared(const A& allocator, std::size_t size) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; T1* p1 = 0; - T3* p2 = 0; + T2* p2 = 0; std::size_t n1 = size * boost::detail::array_total::size; - boost::detail::allocate_array_helper a1(allocator, n1, &p2); - boost::detail::array_deleter d1(n1); + boost::detail::allocate_array_helper a1(allocator, n1, &p2); + boost::detail::array_deleter d1(n1); boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); d2->init(p2); return boost::shared_ptr(s1, p1); } - - template - inline typename boost::detail::sp_if_size_array::type - allocate_shared(const A& allocator) { +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template + inline typename boost::detail::sp_if_array::type + allocate_shared(const A& allocator, std::size_t size, Args&&... args) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::type T2; + T1* p1 = 0; + T2* p2 = 0; + std::size_t n1 = size * boost::detail::array_total::size; + boost::detail::allocate_array_helper a1(allocator, n1, &p2); + boost::detail::array_deleter d1(n1); + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init(p2, boost::detail::sp_forward(args)...); + return boost::shared_ptr(s1, p1); + } + template + inline typename boost::detail::sp_if_size_array::type + allocate_shared(const A& allocator, Args&&... args) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; enum { N = boost::detail::array_total::size }; T1* p1 = 0; - T3* p2 = 0; - boost::detail::allocate_array_helper a1(allocator, &p2); - boost::detail::array_deleter d1; + T2* p2 = 0; + boost::detail::allocate_array_helper a1(allocator, &p2); + boost::detail::array_deleter d1; boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); - d2->init(p2); + d2->init(p2, boost::detail::sp_forward(args)...); + return boost::shared_ptr(s1, p1); + } +#endif +#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + template + inline typename boost::detail::sp_if_size_array::type + allocate_shared(const A& allocator, const T& list) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::type T2; + typedef const T2 T3; + enum { + N = boost::detail::array_total::size + }; + T1* p1 = 0; + T2* p2 = 0; + T3* p3 = 0; + boost::detail::allocate_array_helper a1(allocator, &p2); + boost::detail::array_deleter d1; + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p3 = reinterpret_cast(list); + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init_list(p2, p3); return boost::shared_ptr(s1, p1); } - template inline typename boost::detail::sp_if_array::type allocate_shared(const A& allocator, std::size_t size, - const typename boost::detail::array_inner::type& value) { + const typename boost::detail::array_inner::type& list) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; - typedef const T2 T4; + typedef const T2 T3; enum { M = boost::detail::array_total::size }; T1* p1 = 0; - T3* p2 = 0; - T4* p3 = reinterpret_cast(&value); + T2* p2 = 0; + T3* p3 = 0; std::size_t n1 = M * size; - boost::detail::allocate_array_helper a1(allocator, n1, &p2); - boost::detail::array_deleter d1(n1); + boost::detail::allocate_array_helper a1(allocator, n1, &p2); + boost::detail::array_deleter d1(n1); boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; + p3 = reinterpret_cast(list); p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); - d2->template init(p2, p3); + d2->template init_list(p2, p3); return boost::shared_ptr(s1, p1); } - template inline typename boost::detail::sp_if_size_array::type - allocate_shared(const A& allocator, - const typename boost::detail::array_inner::type& value) { + allocate_shared(const A& allocator, + const typename boost::detail::array_inner::type& list) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; - typedef const T2 T4; + typedef const T2 T3; enum { M = boost::detail::array_total::size, - N = boost::detail::array_total::size + N = boost::detail::array_total::size }; T1* p1 = 0; - T3* p2 = 0; - T4* p3 = reinterpret_cast(&value); - boost::detail::allocate_array_helper a1(allocator, &p2); - boost::detail::array_deleter d1; + T2* p2 = 0; + T3* p3 = 0; + boost::detail::allocate_array_helper a1(allocator, &p2); + boost::detail::array_deleter d1; boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; + p3 = reinterpret_cast(list); p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); - d2->template init(p2, p3); + d2->template init_list(p2, p3); return boost::shared_ptr(s1, p1); } - +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + template + inline typename boost::detail::sp_if_array::type + allocate_shared(const A& allocator, + std::initializer_list::type> list) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::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::size; + boost::detail::allocate_array_helper a1(allocator, n1, &p2); + boost::detail::array_deleter d1(n1); + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p3 = reinterpret_cast(list.begin()); + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init_list(p2, p3); + return boost::shared_ptr(s1, p1); + } +#endif +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template + inline typename boost::detail::sp_if_array::type + allocate_shared(const A& allocator, std::size_t size, + typename boost::detail::array_base::type&& value) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::type T2; + T1* p1 = 0; + T2* p2 = 0; + std::size_t n1 = size * boost::detail::array_total::size; + boost::detail::allocate_array_helper a1(allocator, n1, &p2); + boost::detail::array_deleter d1(n1); + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init(p2, boost::detail::sp_forward(value)); + return boost::shared_ptr(s1, p1); + } + template + inline typename boost::detail::sp_if_size_array::type + allocate_shared(const A& allocator, + typename boost::detail::array_base::type&& value) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::type T2; + enum { + N = boost::detail::array_total::size + }; + T1* p1 = 0; + T2* p2 = 0; + boost::detail::allocate_array_helper a1(allocator, &p2); + boost::detail::array_deleter d1; + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init(p2, boost::detail::sp_forward(value)); + return boost::shared_ptr(s1, p1); + } +#endif +#endif template inline typename boost::detail::sp_if_array::type allocate_shared_noinit(const A& allocator, std::size_t size) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; T1* p1 = 0; - T3* p2 = 0; + T2* p2 = 0; std::size_t n1 = size * boost::detail::array_total::size; - boost::detail::allocate_array_helper a1(allocator, n1, &p2); - boost::detail::array_deleter d1(n1); + boost::detail::allocate_array_helper a1(allocator, n1, &p2); + boost::detail::array_deleter d1(n1); boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); d2->noinit(p2); return boost::shared_ptr(s1, p1); } - template inline typename boost::detail::sp_if_size_array::type allocate_shared_noinit(const A& allocator) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; enum { N = boost::detail::array_total::size }; T1* p1 = 0; - T3* p2 = 0; - boost::detail::allocate_array_helper a1(allocator, &p2); - boost::detail::array_deleter d1; + T2* p2 = 0; + boost::detail::allocate_array_helper a1(allocator, &p2); + boost::detail::array_deleter d1; boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); d2->noinit(p2); diff --git a/include/boost/smart_ptr/detail/allocate_array_helper.hpp b/include/boost/smart_ptr/detail/allocate_array_helper.hpp index 1f358e7..2eeea2d 100644 --- a/include/boost/smart_ptr/detail/allocate_array_helper.hpp +++ b/include/boost/smart_ptr/detail/allocate_array_helper.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -15,15 +15,12 @@ namespace boost { namespace detail { template class allocate_array_helper; - template class allocate_array_helper { template friend class allocate_array_helper; - typedef typename A::template rebind ::other A2; typedef typename A::template rebind::other A3; - public: typedef typename A2::value_type value_type; typedef typename A2::pointer pointer; @@ -32,37 +29,30 @@ namespace boost { typedef typename A2::const_reference const_reference; typedef typename A2::size_type size_type; typedef typename A2::difference_type difference_type; - template struct rebind { typedef allocate_array_helper other; }; - allocate_array_helper(const A& allocator_, std::size_t size_, T** data_) : allocator(allocator_), size(sizeof(T) * size_), data(data_) { } - template allocate_array_helper(const allocate_array_helper& other) : allocator(other.allocator), size(other.size), data(other.data) { } - pointer address(reference value) const { return allocator.address(value); } - const_pointer address(const_reference value) const { return allocator.address(value); } - size_type max_size() const { return allocator.max_size(); } - pointer allocate(size_type count, const void* value = 0) { std::size_t a1 = boost::alignment_of::value; std::size_t n1 = count * sizeof(Y) + a1 - 1; @@ -74,46 +64,37 @@ namespace boost { *data = reinterpret_cast(p2); return reinterpret_cast(p1); } - void deallocate(pointer memory, size_type count) { std::size_t a1 = boost::alignment_of::value; std::size_t n1 = count * sizeof(Y) + a1 - 1; char* p1 = reinterpret_cast(memory); A3(allocator).deallocate(p1, n1 + size); } - void construct(pointer memory, const Y& value) { allocator.construct(memory, value); } - void destroy(pointer memory) { allocator.destroy(memory); } - template bool operator==(const allocate_array_helper& other) const { return allocator == other.allocator; } - template bool operator!=(const allocate_array_helper& other) const { return !(*this == other); } - private: A2 allocator; std::size_t size; T** data; }; - template class allocate_array_helper { template friend class allocate_array_helper; - typedef typename A::template rebind ::other A2; typedef typename A::template rebind::other A3; - public: typedef typename A2::value_type value_type; typedef typename A2::pointer pointer; @@ -122,35 +103,28 @@ namespace boost { typedef typename A2::const_reference const_reference; typedef typename A2::size_type size_type; typedef typename A2::difference_type difference_type; - template struct rebind { typedef allocate_array_helper other; }; - allocate_array_helper(const A& allocator_, T** data_) : allocator(allocator_), data(data_) { } - template allocate_array_helper(const allocate_array_helper& other) : allocator(other.allocator), data(other.data) { } - pointer address(reference value) const { return allocator.address(value); } - const_pointer address(const_reference value) const { return allocator.address(value); } - size_type max_size() const { return allocator.max_size(); } - pointer allocate(size_type count, const void* value = 0) { std::size_t a1 = boost::alignment_of::value; std::size_t n1 = count * sizeof(Y) + a1 - 1; @@ -162,37 +136,30 @@ namespace boost { *data = reinterpret_cast(p2); return reinterpret_cast(p1); } - void deallocate(pointer memory, size_type count) { std::size_t a1 = boost::alignment_of::value; std::size_t n1 = count * sizeof(Y) + a1 - 1; char* p1 = reinterpret_cast(memory); A3(allocator).deallocate(p1, n1 + N1); } - void construct(pointer memory, const Y& value) { allocator.construct(memory, value); } - void destroy(pointer memory) { allocator.destroy(memory); } - template bool operator==(const allocate_array_helper& other) const { return allocator == other.allocator; } - template bool operator!=(const allocate_array_helper& other) const { return !(*this == other); } - private: enum { N1 = N * sizeof(T) }; - A2 allocator; T** data; }; diff --git a/include/boost/smart_ptr/detail/array_deleter.hpp b/include/boost/smart_ptr/detail/array_deleter.hpp index 9d7f970..20f84d1 100644 --- a/include/boost/smart_ptr/detail/array_deleter.hpp +++ b/include/boost/smart_ptr/detail/array_deleter.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -9,14 +9,13 @@ #ifndef BOOST_SMART_PTR_DETAIL_ARRAY_DELETER_HPP #define BOOST_SMART_PTR_DETAIL_ARRAY_DELETER_HPP -#include #include +#include namespace boost { namespace detail { template class array_deleter; - template class array_deleter { public: @@ -24,77 +23,98 @@ namespace boost { : size(size_), object(0) { } - ~array_deleter() { if (object) { array_destroy(object, size); } } - void init(T* memory) { array_init(memory, size); object = memory; } - - template - void init(T* memory, const T* value) { - array_init(memory, size, value); +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + void init(T* memory, T&& value) { + array_init_value(memory, size, sp_forward(value)); + object = memory; + } +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template + void init(T* memory, Args&&... args) { + array_init_args(memory, size, sp_forward(args)...); + object = memory; + } +#endif +#endif + void init_list(T* memory, const T* list) { + array_init_list(memory, size, list); + object = memory; + } + template + void init_list(T* memory, const T* list) { + array_init_list(memory, size, list); object = memory; } - void noinit(T* memory) { array_noinit(memory, size); object = memory; } - void operator()(const void*) { if (object) { array_destroy(object, size); object = 0; } } - private: std::size_t size; T* object; }; - template class array_deleter { public: array_deleter() : object(0) { } - ~array_deleter() { if (object) { array_destroy(object, N); } } - void init(T* memory) { array_init(memory, N); object = memory; } - - template - void init(T* memory, const T* value) { - array_init(memory, N, value); +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + void init(T* memory, T&& value) { + array_init_value(memory, N, sp_forward(value)); + object = memory; + } +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + template + void init(T* memory, Args&&... args) { + array_init_args(memory, N, sp_forward(args)...); + object = memory; + } +#endif +#endif + void init_list(T* memory, const T* list) { + array_init_list(memory, N, list); + object = memory; + } + template + void init_list(T* memory, const T* list) { + array_init_list(memory, N, list); object = memory; } - void noinit(T* memory) { array_noinit(memory, N); object = memory; } - void operator()(const void*) { if (object) { array_destroy(object, N); object = 0; } } - private: T* object; }; diff --git a/include/boost/smart_ptr/detail/array_traits.hpp b/include/boost/smart_ptr/detail/array_traits.hpp index e10ef97..8ef7874 100644 --- a/include/boost/smart_ptr/detail/array_traits.hpp +++ b/include/boost/smart_ptr/detail/array_traits.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -9,47 +9,40 @@ #ifndef BOOST_SMART_PTR_DETAIL_ARRAY_TRAITS_HPP #define BOOST_SMART_PTR_DETAIL_ARRAY_TRAITS_HPP -#include +#include namespace boost { namespace detail { template struct array_base { - typedef T type; + typedef typename boost::remove_cv::type type; }; - template struct array_base { typedef typename array_base::type type; }; - template struct array_base { typedef typename array_base::type type; }; - template struct array_total { enum { size = 1 }; }; - template struct array_total { enum { size = N * array_total::size }; }; - template struct array_inner; - template struct array_inner { typedef T type; }; - template struct array_inner { typedef T type; diff --git a/include/boost/smart_ptr/detail/array_utility.hpp b/include/boost/smart_ptr/detail/array_utility.hpp index d8444b8..3cf36d7 100644 --- a/include/boost/smart_ptr/detail/array_utility.hpp +++ b/include/boost/smart_ptr/detail/array_utility.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -16,36 +16,27 @@ namespace boost { namespace detail { template - inline void array_destroy(T*, std::size_t, - boost::true_type) { + inline void array_destroy(T*, std::size_t, boost::true_type) { } - template - 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; ) { memory[--i].~T(); } } - template inline void array_destroy(T* memory, std::size_t size) { boost::has_trivial_destructor type; array_destroy(memory, size, type); } - template - inline void array_value(T* memory, std::size_t size, - boost::true_type) { + inline void array_init(T* memory, std::size_t size, boost::true_type) { for (std::size_t i = 0; i < size; i++) { - void* p1 = memory + i; - ::new(p1) T(); + memory[i] = T(); } } - template - inline void array_value(T* memory, std::size_t size, - boost::false_type) { + inline void array_init(T* memory, std::size_t size, boost::false_type) { #if !defined(BOOST_NO_EXCEPTIONS) std::size_t i = 0; try { @@ -64,16 +55,77 @@ namespace boost { } #endif } - template inline void array_init(T* memory, std::size_t size) { boost::has_trivial_default_constructor type; - array_value(memory, size, type); + array_init(memory, size, type); + } +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template + 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 + 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 + 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 - inline void array_init(T* memory, std::size_t size, - const T* list) { + 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 { @@ -92,15 +144,11 @@ namespace boost { } #endif } - template - inline void array_default(T*, std::size_t, - boost::true_type) { + inline void array_noinit(T*, std::size_t, boost::true_type) { } - template - inline void array_default(T* memory, std::size_t size, - boost::false_type) { + inline void array_noinit(T* memory, std::size_t size, boost::false_type) { #if !defined(BOOST_NO_EXCEPTIONS) std::size_t i = 0; try { @@ -119,11 +167,10 @@ namespace boost { } #endif } - template inline void array_noinit(T* memory, std::size_t size) { boost::has_trivial_default_constructor type; - array_default(memory, size, type); + array_noinit(memory, size, type); } } } diff --git a/include/boost/smart_ptr/detail/make_array_helper.hpp b/include/boost/smart_ptr/detail/make_array_helper.hpp index cc1fc44..6cf0483 100644 --- a/include/boost/smart_ptr/detail/make_array_helper.hpp +++ b/include/boost/smart_ptr/detail/make_array_helper.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2104 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -15,12 +15,10 @@ namespace boost { namespace detail { template class make_array_helper; - template class make_array_helper { template friend class make_array_helper; - public: typedef Y value_type; typedef Y* pointer; @@ -29,35 +27,28 @@ namespace boost { typedef const Y& const_reference; typedef std::size_t size_type; typedef ptrdiff_t difference_type; - template struct rebind { typedef make_array_helper other; }; - make_array_helper(std::size_t size_, T** data_) : size(sizeof(T) * size_), data(data_) { } - template make_array_helper(const make_array_helper& other) : size(other.size), data(other.data) { } - pointer address(reference value) const { return &value; } - const_pointer address(const_reference value) const { return &value; } - size_type max_size() const { return static_cast(-1) / sizeof(Y); } - pointer allocate(size_type count, const void* = 0) { std::size_t a1 = boost::alignment_of::value; std::size_t n1 = count * sizeof(Y) + a1 - 1; @@ -69,41 +60,33 @@ namespace boost { *data = reinterpret_cast(p2); return reinterpret_cast(p1); } - void deallocate(pointer memory, size_type) { void* p1 = memory; ::operator delete(p1); } - void construct(pointer memory, const Y& value) { void* p1 = memory; ::new(p1) Y(value); } - void destroy(pointer memory) { memory->~Y(); } - template bool operator==(const make_array_helper&) const { return true; } - template bool operator!=(const make_array_helper& other) const { return !(*this == other); } - private: std::size_t size; T** data; }; - template class make_array_helper { template friend class make_array_helper; - public: typedef Y value_type; typedef Y* pointer; @@ -112,33 +95,26 @@ namespace boost { typedef const Y& const_reference; typedef std::size_t size_type; typedef ptrdiff_t difference_type; - template struct rebind { typedef make_array_helper other; }; - make_array_helper(T** data_) : data(data_) { } - template make_array_helper(const make_array_helper& other) : data(other.data) { } - pointer address(reference value) const { return &value; } - const_pointer address(const_reference value) const { return &value; } - size_type max_size() const { return static_cast(-1) / sizeof(Y); } - pointer allocate(size_type count, const void* = 0) { std::size_t a1 = boost::alignment_of::value; std::size_t n1 = count * sizeof(Y) + a1 - 1; @@ -150,36 +126,29 @@ namespace boost { *data = reinterpret_cast(p2); return reinterpret_cast(p1); } - void deallocate(pointer memory, size_type) { void* p1 = memory; ::operator delete(p1); } - void construct(pointer memory, const Y& value) { void* p1 = memory; ::new(p1) Y(value); } - void destroy(pointer memory) { memory->~Y(); } - template bool operator==(const make_array_helper&) const { return true; } - template bool operator!=(const make_array_helper& other) const { return !(*this == other); } - private: enum { N1 = N * sizeof(T) }; - T** data; }; } diff --git a/include/boost/smart_ptr/detail/sp_if_array.hpp b/include/boost/smart_ptr/detail/sp_if_array.hpp index bbd0f3c..661e178 100644 --- a/include/boost/smart_ptr/detail/sp_if_array.hpp +++ b/include/boost/smart_ptr/detail/sp_if_array.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -15,15 +15,12 @@ namespace boost { namespace detail { template struct sp_if_array; - template struct sp_if_array { typedef boost::shared_ptr type; }; - template struct sp_if_size_array; - template struct sp_if_size_array { typedef boost::shared_ptr type; diff --git a/include/boost/smart_ptr/make_shared_array.hpp b/include/boost/smart_ptr/make_shared_array.hpp index 6a0bcfd..eb0578d 100644 --- a/include/boost/smart_ptr/make_shared_array.hpp +++ b/include/boost/smart_ptr/make_shared_array.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -9,11 +9,14 @@ #ifndef BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP #define BOOST_SMART_PTR_MAKE_SHARED_ARRAY_HPP +#include #include #include #include #include -#include +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) +#include +#endif namespace boost { template @@ -21,124 +24,219 @@ namespace boost { make_shared(std::size_t size) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; T1* p1 = 0; - T3* p2 = 0; + T2* p2 = 0; std::size_t n1 = size * boost::detail::array_total::size; - boost::detail::make_array_helper a1(n1, &p2); - boost::detail::array_deleter d1(n1); + boost::detail::make_array_helper a1(n1, &p2); + boost::detail::array_deleter d1(n1); boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); d2->init(p2); return boost::shared_ptr(s1, p1); } - - template - inline typename boost::detail::sp_if_size_array::type - make_shared() { +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template + inline typename boost::detail::sp_if_array::type + make_shared(std::size_t size, Args&&... args) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::type T2; + T1* p1 = 0; + T2* p2 = 0; + std::size_t n1 = size * boost::detail::array_total::size; + boost::detail::make_array_helper a1(n1, &p2); + boost::detail::array_deleter d1(n1); + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init(p2, boost::detail::sp_forward(args)...); + return boost::shared_ptr(s1, p1); + } + template + inline typename boost::detail::sp_if_size_array::type + make_shared(Args&&... args) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; enum { N = boost::detail::array_total::size }; T1* p1 = 0; - T3* p2 = 0; - boost::detail::make_array_helper a1(&p2); - boost::detail::array_deleter d1; + T2* p2 = 0; + boost::detail::make_array_helper a1(&p2); + boost::detail::array_deleter d1; boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); - d2->init(p2); + d2->init(p2, boost::detail::sp_forward(args)...); + return boost::shared_ptr(s1, p1); + } +#endif +#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) + template + inline typename boost::detail::sp_if_size_array::type + make_shared(const T& list) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::type T2; + typedef const T2 T3; + enum { + N = boost::detail::array_total::size + }; + T1* p1 = 0; + T2* p2 = 0; + T3* p3 = 0; + boost::detail::make_array_helper a1(&p2); + boost::detail::array_deleter d1; + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p3 = reinterpret_cast(list); + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init_list(p2, p3); return boost::shared_ptr(s1, p1); } - template inline typename boost::detail::sp_if_array::type make_shared(std::size_t size, - const typename boost::detail::array_inner::type& value) { + const typename boost::detail::array_inner::type& list) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; - typedef const T2 T4; + typedef const T2 T3; enum { M = boost::detail::array_total::size }; T1* p1 = 0; - T3* p2 = 0; - T4* p3 = reinterpret_cast(&value); + T2* p2 = 0; + T3* p3 = 0; std::size_t n1 = M * size; - boost::detail::make_array_helper a1(n1, &p2); - boost::detail::array_deleter d1(n1); + boost::detail::make_array_helper a1(n1, &p2); + boost::detail::array_deleter d1(n1); boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; + p3 = reinterpret_cast(list); p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); - d2->template init(p2, p3); + d2->template init_list(p2, p3); return boost::shared_ptr(s1, p1); } - template inline typename boost::detail::sp_if_size_array::type - make_shared(const typename boost::detail::array_inner::type& value) { + make_shared(const typename boost::detail::array_inner::type& list) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; - typedef const T2 T4; + typedef const T2 T3; enum { M = boost::detail::array_total::size, N = boost::detail::array_total::size }; T1* p1 = 0; - T3* p2 = 0; - T4* p3 = reinterpret_cast(&value); - boost::detail::make_array_helper a1(&p2); - boost::detail::array_deleter d1; + T2* p2 = 0; + T3* p3 = 0; + boost::detail::make_array_helper a1(&p2); + boost::detail::array_deleter d1; boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; + p3 = reinterpret_cast(list); p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); - d2->template init(p2, p3); + d2->template init_list(p2, p3); return boost::shared_ptr(s1, p1); } - +#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + template + inline typename boost::detail::sp_if_array::type + make_shared(std::initializer_list::type> list) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::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::size; + boost::detail::make_array_helper a1(n1, &p2); + boost::detail::array_deleter d1(n1); + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p3 = reinterpret_cast(list.begin()); + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init_list(p2, p3); + return boost::shared_ptr(s1, p1); + } +#endif +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template + inline typename boost::detail::sp_if_array::type + make_shared(std::size_t size, + typename boost::detail::array_base::type&& value) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::type T2; + T1* p1 = 0; + T2* p2 = 0; + std::size_t n1 = size * boost::detail::array_total::size; + boost::detail::make_array_helper a1(n1, &p2); + boost::detail::array_deleter d1(n1); + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init(p2, boost::detail::sp_forward(value)); + return boost::shared_ptr(s1, p1); + } + template + inline typename boost::detail::sp_if_size_array::type + make_shared(typename boost::detail::array_base::type&& value) { + typedef typename boost::detail::array_inner::type T1; + typedef typename boost::detail::array_base::type T2; + enum { + N = boost::detail::array_total::size + }; + T1* p1 = 0; + T2* p2 = 0; + boost::detail::make_array_helper a1(&p2); + boost::detail::array_deleter d1; + boost::shared_ptr s1(p1, d1, a1); + typedef boost::detail::array_deleter* D2; + p1 = reinterpret_cast(p2); + D2 d2 = static_cast(s1._internal_get_untyped_deleter()); + d2->init(p2, boost::detail::sp_forward(value)); + return boost::shared_ptr(s1, p1); + } +#endif +#endif template inline typename boost::detail::sp_if_array::type make_shared_noinit(std::size_t size) { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; T1* p1 = 0; - T3* p2 = 0; + T2* p2 = 0; std::size_t n1 = size * boost::detail::array_total::size; - boost::detail::make_array_helper a1(n1, &p2); - boost::detail::array_deleter d1(n1); + boost::detail::make_array_helper a1(n1, &p2); + boost::detail::array_deleter d1(n1); boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); d2->noinit(p2); return boost::shared_ptr(s1, p1); } - template inline typename boost::detail::sp_if_size_array::type make_shared_noinit() { typedef typename boost::detail::array_inner::type T1; typedef typename boost::detail::array_base::type T2; - typedef typename boost::remove_cv::type T3; enum { N = boost::detail::array_total::size }; T1* p1 = 0; - T3* p2 = 0; - boost::detail::make_array_helper a1(&p2); - boost::detail::array_deleter d1; + T2* p2 = 0; + boost::detail::make_array_helper a1(&p2); + boost::detail::array_deleter d1; boost::shared_ptr s1(p1, d1, a1); - typedef boost::detail::array_deleter* D2; + typedef boost::detail::array_deleter* D2; p1 = reinterpret_cast(p2); D2 d2 = static_cast(s1._internal_get_untyped_deleter()); d2->noinit(p2); diff --git a/make_shared_array.html b/make_shared_array.html index 6959ca1..3437e9e 100644 --- a/make_shared_array.html +++ b/make_shared_array.html @@ -5,7 +5,7 @@ -

boost.png (6897 bytes)boost.png (6897 bytes)make_shared and allocate_shared for arrays

Introduction
@@ -29,69 +29,103 @@ allowing finer control.

Synopsis

namespace boost {
-    template<typename U> // U is T[]
+    template<typename U> // U = T[]
     shared_ptr<U> make_shared(size_t size);
 
-    template<typename U, typename A> // U is T[]
+    template<typename U, typename A> // U = T[]
     shared_ptr<U> allocate_shared(const A& allocator, size_t size);
-    
-    template<typename U> // U is T[N]
-    shared_ptr<U> make_shared();
 
-    template<typename U, typename A> // U is T[N]
-    shared_ptr<U> allocate_shared(const A& allocator);
-   
-    template<typename U> // U is T[]
-    shared_ptr<U> make_shared(size_t size, const T& value);
+#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)   
+    template<typename U, typename... Args> // U = T[]
+    shared_ptr<U> make_shared(size_t size, Args&&... args);
 
-    template<typename U, typename A> // U is T[]
-    shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T& value);
+    template<typename U, typename... Args> // U = T[N]
+    shared_ptr<U> make_shared(Args&&... args);
 
-    template<typename U> // U is T[N]
-    shared_ptr<U> make_shared(const T& value);
+    template<typename U, typename A, typename... Args> // U = T[]
+    shared_ptr<U> allocate_shared(const A& allocator, size_t size, Args&&... args);
 
-    template<typename U, typename A> // U is T[N]
-    shared_ptr<U> allocate_shared(const A& allocator, const T& value);
+    template<typename U, typename A, typename... Args> // U = T[N]
+    shared_ptr<U> allocate_shared(const A& allocator, Args&&... args);
+#endif
 
-    template<typename U> // U is T[]
+#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)    
+    template<typename U, typename... Args> // U = T[N]
+    shared_ptr<U> make_shared(const T (&list)[N]);
+
+    template<typename U, typename... Args> // U = T[][N]
+    shared_ptr<U> make_shared(size_t size, const T (&list)[N]);
+
+    template<typename U, typename... Args> // U = T[M][N]
+    shared_ptr<U> make_shared(const T (&list)[N]);
+
+    template<typename U, typename A, typename... Args> // U = T[N]
+    shared_ptr<T[> allocate_shared(const A& allocator, const T (&list)[N]);
+
+    template<typename U, typename A, typename... Args> // U = T[][N]
+    shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T (&list)[N]);
+
+    template<typename U, typename A, typename... Args> // U = T[M][N]
+    shared_ptr<U> allocate_shared(const A& allocator, const T (&list)[N]);
+
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+    template<typename U, typename... Args> // U = T[]
+    shared_ptr<U> make_shared(initializer_list<T> list);
+
+    template<typename U, typename A, typename... Args> // U = T[]
+    shared_ptr<U> allocate_shared(const A& allocator, initializer_list<T> list);
+#endif
+
+#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)    
+    template<typename U> // U = T[]
+    shared_ptr<U> make_shared(size_t size, T&& value);
+
+    template<typename U> // U = T[N]
+    shared_ptr<U> make_shared(T&& value);
+
+    template<typename U, typename A> // U = T[]
+    shared_ptr<U> allocate_shared(const A& allocator, size_t size, T&& value);
+
+    template<typename U, typename A> // U = T[N]
+    shared_ptr<U> allocate_shared(const A& allocator, T&& value);
+#endif
+#endif
+
+    template<typename U> // U = T[]
     shared_ptr<U> make_shared_noinit(size_t size);
 
-    template<typename U, typename A> // U is T[]
-    shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size);
-
-    template<typename U> // U is T[N]
+    template<typename U> // U = T[N]
     shared_ptr<U> make_shared_noinit();
 
-    template<typename U, typename A> // U is T[N]
+    template<typename U, typename A> // U = T[]
+    shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size);
+
+    template<typename U, typename A> // U = T[N]
     shared_ptr<U> allocate_shared_noinit(const A& allocator);
 }

Free Functions

-
template<typename U> // U is T[]
-shared_ptr<U> make_shared(size_t size);
+    
template<typename U, typename... Args> // U = T[]
+shared_ptr<U> make_shared(size_t size, Args&&... args);
 
-template<typename U, typename A> // U is T[]
-shared_ptr<U> allocate_shared(const A& allocator, size_t size);
-
-template<typename U> // U is T[N]
-shared_ptr<U> make_shared();
-
-template<typename U, typename A> // U is T[N]
-shared_ptr<U> allocate_shared(const A& allocator);
+template<typename U, typename A, typename... Args> // U = T[] +shared_ptr<U> allocate_shared(const A& allocator, size_t size, Args&&... args);

Requires: The expression - new(pointer) T(), where pointer is a - void* pointing to storage suitable to hold an object - of type T, shall be well-formed. A - shall be an Allocator, as described in section 20.1.5 - (Allocator requirements) of the C++ Standard. - The copy constructor and destructor of A shall not - throw.

+ new(pointer) T(forward<Args>(args)...), where + pointer is a void* pointing to storage + suitable to hold an object of type T, shall be + well-formed. A shall be an Allocator, as + described in section 20.1.5 (Allocator requirements) + of the C++ Standard. The copy constructor and destructor of + A shall not throw.

Effects: Allocates memory suitable for an array of type T and size size and constructs an array of objects in it via the placement new expression - new(pointer) T(). allocate_shared uses - a copy of allocator to allocate memory. If an - exception is thrown, has no effect.

+ new(pointer) T() or + new(pointer) T(args...). + allocate_shared uses a copy of + allocator to allocate memory. If an exception is thrown, + has no effect.

Returns: A shared_ptr instance that stores and owns the address of the newly constructed array of type T and size size.

@@ -103,63 +137,121 @@ shared_ptr<U> allocate_shared(const A& allocator); the returned shared_ptr and an array of type T of size size in a single allocation. This provides efficiency to equivalent to an intrusive smart array - pointer.

+ pointer.

+

The prototypes shown above are used if your compiler supports r-value + references and variadic templates. They perfectly forward the + args parameters to the constructors of + T for each array element.

+

Otherwise, you can use the overloads which take only the array size + (and the allocator in case of allocate_shared) and do not + take any constructor arguments. These overloads invoke the default + constructor of T for each array element.

-
template<typename U> // U is T[]
-shared_ptr<U> make_shared(size_t size, const T& value);
+    
template<typename U, typename... Args> // U = T[N]
+shared_ptr<U> make_shared(Args&&... args);
 
-template<typename U, typename A> // U is T[]
-shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T& value);
+template<typename U, typename A, typename... Args> // U = T[N]
+shared_ptr<U> allocate_shared(const A& allocator, Args&&... args);
+
+

Description: These overloads of the utilities above are for a + fixed size array.

+
+
template<typename U, typename... Args> // U = T[]
+shared_ptr<U> make_shared(initializer_list<T> list);
 
-template<typename U> // U is T[N]
-shared_ptr<U> make_shared(const T& value);
+template<typename U, typename A, typename... Args> // U = T[]
+shared_ptr<U> allocate_shared(const A& allocator, initializer_list<T> list);
+
+

Description: These overloads initialize the array elements + from the initializer list.

+
+
template<typename U, typename... Args> // U = T[N]
+shared_ptr<U> make_shared(const T (&list)[N]);
 
-template<typename U, typename A> // U is T[N]
-shared_ptr<U> allocate_shared(const A& allocator, const T& value);
+template<typename U, typename A, typename... Args> // U = T[N] +shared_ptr<U> allocate_shared(const A& allocator, const T (&list)[N]);
+
+

Description: These overloads of the utilities above are for a + fixed size array.

+
+
template<typename U, typename... Args> // U = T[][N]
+shared_ptr<U> make_shared(size_t size, const T (&list)[N]);
+
+template<typename U, typename A, typename... Args> // U = T[][N]
+shared_ptr<U> allocate_shared(const A& allocator, size_t size, const T (&list)[N]);
+
+

Description: These overloads initialize inner array elements + from the initializer list.

+
+
template<typename U, typename... Args> // U = T[M][N]
+shared_ptr<U> make_shared(const T (&list)[N]);
+
+template<typename U, typename A, typename... Args> // U = T[M][N]
+shared_ptr<U> allocate_shared(const A& allocator, const T (&list)[N]);
+
+

Description: These overloads of the utilities above are for a + fixed size array.

+
+
template<typename U> // U = T[]
+shared_ptr<U> make_shared(size_t size, T&& value);
+
+template<typename U, typename A> // U = T[]
+shared_ptr<U> allocate_shared(const A& allocator, size_t size, T&& value);

Description: These overloads initialize array elements with the given value.

-
template<typename U> // U is T[]
+    
template<typename U> // U = T[N]
+shared_ptr<U> make_shared(T&& value);
+
+template<typename U, typename A> // U = T[N]
+shared_ptr<U> allocate_shared(const A& allocator, T&& value);
+
+

Description: These overloads of the utilities above are for a + fixed size array.

+
+
template<typename U> // U = T[]
 shared_ptr<U> make_shared_noinit(size_t size);
 
-template<typename U, typename A> // U is T[]
-shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size);
-
-template<typename U> // U is T[N]
-shared_ptr<U> make_shared_noinit();
-
-template<typename U, typename A> // U is T[N]
-shared_ptr<U> allocate_shared_noinit(const A& allocator);
+template<typename U, typename A> // U = T[] +shared_ptr<U> allocate_shared_noinit(const A& allocator, size_t size);

Description: These overloads do not perform any value initialization of elements.

-
-

Examples

-

Some examples of each overload of make_shared for arrays:

+ +
template<typename U> // U = T[N]
+shared_ptr<U> make_shared_noinit();
+
+template<typename U, typename A> // U = T[N]
+shared_ptr<U> allocate_shared_noinit(const A& allocator);
+
+

Description: These overloads of the utilities above are for a + fixed size array.

+
+

Example

+

An example of each overload of make_shared for arrays:

boost::shared_ptr<int[]> a1 = boost::make_shared<int[]>(size);
-boost::shared_ptr<int[8]> a2 = boost::make_shared<int[8]>();
-boost::shared_ptr<int[][2]> a3 = boost::make_shared<int[][2]>(size);
-boost::shared_ptr<int[4][2]> a4 = boost::make_shared<int[4][2]>();
-boost::shared_ptr<int[]> a5 = boost::make_shared<int[]>(size, 1);
-boost::shared_ptr<int[8]> a6 = boost::make_shared<int[8]>(1);
-boost::shared_ptr<int[][2]> a7 = boost::make_shared<int[][2]>(size, {1, 2});
-boost::shared_ptr<int[4][2]> a8 = boost::make_shared<int[4][2]>({1, 2});
-boost::shared_ptr<int[]> a9 = boost::make_shared_noinit<int[]>(size);
-boost::shared_ptr<int[8]> a10 = boost::make_shared_noinit<int[8]>();
-boost::shared_ptr<int[][2]> a11 = boost::make_shared_noinit<int[][2]>(size);
-boost::shared_ptr<int[4][2]> a12 = boost::make_shared_noinit<int[4][2]>();
+boost::shared_ptr<point[]> a2 = boost::make_shared<point[]>(size, x, y); +boost::shared_ptr<point[5]> a3 = boost::make_shared<point[5]>(x, y); +boost::shared_ptr<int[]> a4 = boost::make_shared<int[]>({1, 2, 3}); +boost::shared_ptr<int[3]> a5 = boost::make_shared<int[3]>({1, 2, 3}); +boost::shared_ptr<int[][3]> a6 = boost::make_shared<int[][3]>(size, {1, 2, 3}); +boost::shared_ptr<int[5][3]> a7 = boost::make_shared<int[5][3]>({1, 2, 3}); +boost::shared_ptr<point[]> a8 = boost::make_shared<point[]>(size, {x, y}); +boost::shared_ptr<point[5]> a9 = boost::make_shared<point[5]>({x, y}); +boost::shared_ptr<int[]> a10 = boost::make_shared_noinit<int[]>(size); +boost::shared_ptr<int[5]> a11 = boost::make_shared_noinit<int[5]>();

History

November 2012. Glen Fernandes contributed implementations of make_shared and allocate_shared for arrays.


-

$Date: 2014-01-20 11:10:00 -0800 (Mon, 20 Jan 2014) $

-

Copyright 2012-2014 Glen Fernandes. 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.

+

$Date: 2012-10-30 10:12:25 -0800 (Tue, 30 Oct 2012) $

+

Copyright 2012 Glen Fernandes. 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.

diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 0a57a20..874968a 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -136,16 +136,22 @@ import testing ; [ compile-fail array_fail_array_access.cpp ] [ run make_shared_array_test.cpp ] - [ run make_shared_arrays_test.cpp : : : gcc-4.6.3_0x:-fno-deduce-init-list ] + [ run make_shared_arrays_test.cpp ] + [ run make_shared_array_create_test.cpp ] + [ run make_shared_array_init_test.cpp : : : gcc-4.6.3_0x:-fno-deduce-init-list ] + [ run make_shared_arrays_create_test.cpp : : : gcc-4.6.3_0x:-fno-deduce-init-list ] + [ run make_shared_arrays_init_test.cpp : : : gcc-4.6.3_0x:-fno-deduce-init-list ] [ run make_shared_array_throws_test.cpp ] [ run make_shared_array_esft_test.cpp ] - [ run make_shared_array_noinit_test.cpp ] - [ run make_shared_array_value_test.cpp ] + [ run make_shared_array_args_test.cpp ] [ run allocate_shared_array_test.cpp ] - [ run allocate_shared_arrays_test.cpp : : : gcc-4.6.3_0x:-fno-deduce-init-list ] + [ run allocate_shared_arrays_test.cpp ] + [ run allocate_shared_array_create_test.cpp ] + [ run allocate_shared_array_init_test.cpp : : : gcc-4.6.3_0x:-fno-deduce-init-list ] + [ run allocate_shared_arrays_create_test.cpp : : : gcc-4.6.3_0x:-fno-deduce-init-list ] + [ run allocate_shared_arrays_init_test.cpp : : : gcc-4.6.3_0x:-fno-deduce-init-list ] [ run allocate_shared_array_throws_test.cpp ] [ run allocate_shared_array_esft_test.cpp ] - [ run allocate_shared_array_noinit_test.cpp ] - [ run allocate_shared_array_value_test.cpp ] + [ run allocate_shared_array_args_test.cpp ] ; } diff --git a/test/allocate_shared_array_args_test.cpp b/test/allocate_shared_array_args_test.cpp new file mode 100644 index 0000000..f3d38b6 --- /dev/null +++ b/test/allocate_shared_array_args_test.cpp @@ -0,0 +1,173 @@ +// 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 +#include +#include +#include +#include + +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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(), 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(); +} diff --git a/test/allocate_shared_array_create_test.cpp b/test/allocate_shared_array_create_test.cpp new file mode 100644 index 0000000..90b6b96 --- /dev/null +++ b/test/allocate_shared_array_create_test.cpp @@ -0,0 +1,114 @@ +/* + * 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 +#include + +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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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(); +} diff --git a/test/allocate_shared_array_esft_test.cpp b/test/allocate_shared_array_esft_test.cpp index b342366..cea73c6 100644 --- a/test/allocate_shared_array_esft_test.cpp +++ b/test/allocate_shared_array_esft_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -14,15 +14,12 @@ class type : public boost::enable_shared_from_this { public: static unsigned int instances; - explicit type() { instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -41,7 +38,6 @@ int main() { BOOST_TEST(type::instances == 3); } } - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); @@ -52,6 +48,5 @@ int main() { BOOST_TEST(type::instances == 3); } } - return boost::report_errors(); } diff --git a/test/allocate_shared_array_init_test.cpp b/test/allocate_shared_array_init_test.cpp new file mode 100644 index 0000000..c75b41f --- /dev/null +++ b/test/allocate_shared_array_init_test.cpp @@ -0,0 +1,84 @@ +/* + * 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 +#include + +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 a1 = boost::allocate_shared(std::allocator(), { 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 a1 = boost::allocate_shared(std::allocator(), { 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 a1 = boost::allocate_shared(std::allocator(), { 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 a1 = boost::allocate_shared(std::allocator(), { 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 a1 = boost::allocate_shared(std::allocator(), { 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 a1 = boost::allocate_shared(std::allocator(), { 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 a1 = boost::allocate_shared(std::allocator(), { 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 a1 = boost::allocate_shared(std::allocator(), { 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(); +} diff --git a/test/allocate_shared_array_noinit_test.cpp b/test/allocate_shared_array_noinit_test.cpp deleted file mode 100644 index 6c8ff3d..0000000 --- a/test/allocate_shared_array_noinit_test.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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 -#include -#include -#include - -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 a1 = boost::allocate_shared_noinit(std::allocator(), 3); - int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - } - - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - } - - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - } - - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - } - - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); - const int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - } - - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - const int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - } - - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - } - - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); - type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 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 a1 = boost::allocate_shared_noinit(std::allocator()); - 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 a1 = boost::allocate_shared_noinit(std::allocator(), 3); - const type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); - const type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 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 a1 = boost::allocate_shared_noinit(std::allocator()); - 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(); -} diff --git a/test/allocate_shared_array_test.cpp b/test/allocate_shared_array_test.cpp index 43715a7..f27e5e8 100644 --- a/test/allocate_shared_array_test.cpp +++ b/test/allocate_shared_array_test.cpp @@ -1,9 +1,9 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * 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 + * 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 @@ -14,18 +14,17 @@ class type { public: static unsigned int instances; - - explicit type() { + 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; @@ -41,38 +40,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); - } - - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator()); - 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 a1 = boost::allocate_shared(std::allocator(), 3); const int* a2 = a1.get(); @@ -83,38 +50,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - const int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); - } - - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator()); - 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::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); @@ -127,40 +62,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator()); - 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 a1 = boost::allocate_shared(std::allocator(), 3); @@ -172,10 +73,109 @@ int main() { 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 a1 = boost::allocate_shared(std::allocator()); + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 1, 5); + type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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::value == 0); + BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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::value == 0); + BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); + } +#endif + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); + int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); + int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); + const int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); + const int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); + type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); + type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); const type* a2 = a1.get(); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a2 != 0); @@ -184,26 +184,16 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2); - BOOST_TEST(a1.get() != 0); + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); + const type* a2 = a1.get(); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 4); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); - 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(); } diff --git a/test/allocate_shared_array_throws_test.cpp b/test/allocate_shared_array_throws_test.cpp index 71a3ce9..bb5ac52 100644 --- a/test/allocate_shared_array_throws_test.cpp +++ b/test/allocate_shared_array_throws_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -12,18 +12,15 @@ class type { public: static unsigned int instances; - explicit type() { if (instances == 5) { throw true; } instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -39,7 +36,6 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); try { boost::allocate_shared(std::allocator(), 3); @@ -47,7 +43,7 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) BOOST_TEST(type::instances == 0); try { boost::allocate_shared(std::allocator()); @@ -55,7 +51,6 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); try { boost::allocate_shared(std::allocator()); @@ -63,7 +58,7 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - +#endif BOOST_TEST(type::instances == 0); try { boost::allocate_shared_noinit(std::allocator(), 6); @@ -71,7 +66,6 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); try { boost::allocate_shared_noinit(std::allocator(), 3); @@ -79,22 +73,5 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); - try { - boost::allocate_shared_noinit(std::allocator()); - BOOST_ERROR("allocate_shared_noinit did not throw"); - } catch (...) { - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - try { - boost::allocate_shared_noinit(std::allocator()); - BOOST_ERROR("allocate_shared_noinit did not throw"); - } catch (...) { - BOOST_TEST(type::instances == 0); - } - return boost::report_errors(); } diff --git a/test/allocate_shared_array_value_test.cpp b/test/allocate_shared_array_value_test.cpp deleted file mode 100644 index c1b8b7c..0000000 --- a/test/allocate_shared_array_value_test.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 -#include - -int main() { - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); - } - - { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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(); -} diff --git a/test/allocate_shared_arrays_create_test.cpp b/test/allocate_shared_arrays_create_test.cpp new file mode 100644 index 0000000..a7e95d7 --- /dev/null +++ b/test/allocate_shared_arrays_create_test.cpp @@ -0,0 +1,94 @@ +/* + * 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 +#include + +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 a1 = boost::allocate_shared(std::allocator(), {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 a1 = boost::allocate_shared(std::allocator(), { {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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), {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 a1 = boost::allocate_shared(std::allocator(), { {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 a1 = boost::allocate_shared(std::allocator(), {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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), {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(); +} diff --git a/test/allocate_shared_arrays_init_test.cpp b/test/allocate_shared_arrays_init_test.cpp new file mode 100644 index 0000000..76173fa --- /dev/null +++ b/test/allocate_shared_arrays_init_test.cpp @@ -0,0 +1,23 @@ +/* + * 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 +#include + +int main() { +#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + { + boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { {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(); +} diff --git a/test/allocate_shared_arrays_test.cpp b/test/allocate_shared_arrays_test.cpp index 9dfc866..c0746d3 100644 --- a/test/allocate_shared_arrays_test.cpp +++ b/test/allocate_shared_arrays_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -9,40 +9,152 @@ #include #include +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() { -#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), { 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 a1 = boost::allocate_shared(std::allocator(), 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 - + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 2); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + } + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + } + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 2); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + } + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator()); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 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 a1 = boost::allocate_shared_noinit(std::allocator()); + 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 a1 = boost::allocate_shared_noinit(std::allocator(), 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 a1 = boost::allocate_shared_noinit(std::allocator()); + 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(); } diff --git a/test/make_shared_array_args_test.cpp b/test/make_shared_array_args_test.cpp new file mode 100644 index 0000000..8a89429 --- /dev/null +++ b/test/make_shared_array_args_test.cpp @@ -0,0 +1,172 @@ +// 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 +#include +#include +#include + +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(); +} diff --git a/test/make_shared_array_create_test.cpp b/test/make_shared_array_create_test.cpp new file mode 100644 index 0000000..0bdd635 --- /dev/null +++ b/test/make_shared_array_create_test.cpp @@ -0,0 +1,114 @@ +/* + * 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 +#include + +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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared(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(); +} diff --git a/test/make_shared_array_esft_test.cpp b/test/make_shared_array_esft_test.cpp index a93f760..9d0adb1 100644 --- a/test/make_shared_array_esft_test.cpp +++ b/test/make_shared_array_esft_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -14,15 +14,12 @@ class type : public boost::enable_shared_from_this { public: static unsigned int instances; - explicit type() { instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -41,7 +38,6 @@ int main() { BOOST_TEST(type::instances == 3); } } - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(3); @@ -52,6 +48,5 @@ int main() { BOOST_TEST(type::instances == 3); } } - return boost::report_errors(); } diff --git a/test/make_shared_array_init_test.cpp b/test/make_shared_array_init_test.cpp new file mode 100644 index 0000000..11dcb1c --- /dev/null +++ b/test/make_shared_array_init_test.cpp @@ -0,0 +1,84 @@ +/* + * 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 +#include + +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 a1 = boost::make_shared({ 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 a1 = boost::make_shared({ 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 a1 = boost::make_shared({ 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 a1 = boost::make_shared({ 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 a1 = boost::make_shared({ 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 a1 = boost::make_shared({ 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 a1 = boost::make_shared({ 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 a1 = boost::make_shared({ 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(); +} diff --git a/test/make_shared_array_noinit_test.cpp b/test/make_shared_array_noinit_test.cpp deleted file mode 100644 index 98bd450..0000000 --- a/test/make_shared_array_noinit_test.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* - * 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 -#include -#include -#include - -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 a1 = boost::make_shared_noinit(3); - int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - } - - { - boost::shared_ptr a1 = boost::make_shared_noinit(); - int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - } - - { - boost::shared_ptr a1 = boost::make_shared_noinit(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - } - - { - boost::shared_ptr a1 = boost::make_shared_noinit(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - } - - { - boost::shared_ptr a1 = boost::make_shared_noinit(3); - const int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - } - - { - boost::shared_ptr a1 = boost::make_shared_noinit(); - const int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - } - - { - boost::shared_ptr a1 = boost::make_shared_noinit(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - } - - { - boost::shared_ptr a1 = boost::make_shared_noinit(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1.use_count() == 1); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::make_shared_noinit(3); - type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::make_shared_noinit(); - type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::make_shared_noinit(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 a1 = boost::make_shared_noinit(); - 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 a1 = boost::make_shared_noinit(3); - const type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::make_shared_noinit(); - const type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::make_shared_noinit(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 a1 = boost::make_shared_noinit(); - 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(); -} diff --git a/test/make_shared_array_test.cpp b/test/make_shared_array_test.cpp index ebb76c7..8193553 100644 --- a/test/make_shared_array_test.cpp +++ b/test/make_shared_array_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -14,18 +14,17 @@ class type { public: static unsigned int instances; - - explicit type() { + 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; @@ -41,38 +40,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - - { - boost::shared_ptr a1 = boost::make_shared(); - int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); - } - - { - boost::shared_ptr a1 = boost::make_shared(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 a1 = boost::make_shared(); - 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 a1 = boost::make_shared(3); const int* a2 = a1.get(); @@ -83,38 +50,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - - { - boost::shared_ptr a1 = boost::make_shared(); - const int* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); - } - - { - boost::shared_ptr a1 = boost::make_shared(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 a1 = boost::make_shared(); - 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::shared_ptr a1 = boost::make_shared(3); @@ -127,40 +62,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::make_shared(); - type* a2 = a1.get(); - BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(a2 != 0); - BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); - BOOST_TEST(type::instances == 3); - boost::weak_ptr w1 = a1; - a1.reset(); - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::make_shared(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 a1 = boost::make_shared(); - 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 a1 = boost::make_shared(3); @@ -172,10 +73,109 @@ int main() { 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 a1 = boost::make_shared(); + boost::shared_ptr a1 = boost::make_shared(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::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(1, 5); + type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(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::value == 0); + BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared(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::value == 0); + BOOST_TEST(type::instances == 3); + a1.reset(); + BOOST_TEST(type::instances == 0); + } +#endif + { + boost::shared_ptr a1 = boost::make_shared_noinit(3); + int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + { + boost::shared_ptr a1 = boost::make_shared_noinit(); + int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + { + boost::shared_ptr a1 = boost::make_shared_noinit(3); + const int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + { + boost::shared_ptr a1 = boost::make_shared_noinit(); + const int* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared_noinit(3); + type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared_noinit(); + type* a2 = a1.get(); + BOOST_TEST(a1.use_count() == 1); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); + boost::weak_ptr w1 = a1; + a1.reset(); + BOOST_TEST(type::instances == 0); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared_noinit(3); const type* a2 = a1.get(); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a2 != 0); @@ -184,26 +184,16 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - boost::shared_ptr a1 = boost::make_shared(2); - BOOST_TEST(a1.get() != 0); + boost::shared_ptr a1 = boost::make_shared_noinit(); + const type* a2 = a1.get(); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 4); + BOOST_TEST(a2 != 0); + BOOST_TEST(size_t(a2) % boost::alignment_of::value == 0); + BOOST_TEST(type::instances == 3); a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); - { - boost::shared_ptr a1 = boost::make_shared(); - 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(); } diff --git a/test/make_shared_array_throws_test.cpp b/test/make_shared_array_throws_test.cpp index 151ab31..69e9b88 100644 --- a/test/make_shared_array_throws_test.cpp +++ b/test/make_shared_array_throws_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -12,18 +12,15 @@ class type { public: static unsigned int instances; - explicit type() { if (instances == 5) { throw true; } instances++; } - ~type() { instances--; } - private: type(const type&); type& operator=(const type&); @@ -39,7 +36,6 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); try { boost::make_shared(3); @@ -47,7 +43,7 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) BOOST_TEST(type::instances == 0); try { boost::make_shared(); @@ -55,7 +51,6 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); try { boost::make_shared(); @@ -63,7 +58,7 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - +#endif BOOST_TEST(type::instances == 0); try { boost::make_shared_noinit(6); @@ -71,7 +66,6 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); try { boost::make_shared_noinit(3); @@ -79,22 +73,5 @@ int main() { } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); - try { - boost::make_shared_noinit(); - BOOST_ERROR("make_shared_noinit did not throw"); - } catch (...) { - BOOST_TEST(type::instances == 0); - } - - BOOST_TEST(type::instances == 0); - try { - boost::make_shared_noinit(); - BOOST_ERROR("make_shared_noinit did not throw"); - } catch (...) { - BOOST_TEST(type::instances == 0); - } - return boost::report_errors(); } diff --git a/test/make_shared_array_value_test.cpp b/test/make_shared_array_value_test.cpp deleted file mode 100644 index f042ede..0000000 --- a/test/make_shared_array_value_test.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 -#include - -int main() { - { - boost::shared_ptr a1 = boost::make_shared(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 a1 = boost::make_shared(1); - BOOST_TEST(a1[0] == 1); - BOOST_TEST(a1[1] == 1); - BOOST_TEST(a1[2] == 1); - BOOST_TEST(a1[3] == 1); - } - - { - boost::shared_ptr a1 = boost::make_shared(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 a1 = boost::make_shared(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(); -} diff --git a/test/make_shared_arrays_create_test.cpp b/test/make_shared_arrays_create_test.cpp new file mode 100644 index 0000000..c6a1b4f --- /dev/null +++ b/test/make_shared_arrays_create_test.cpp @@ -0,0 +1,94 @@ +/* + * 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 +#include + +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 a1 = boost::make_shared({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 a1 = boost::make_shared({ {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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared({ 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 a1 = boost::make_shared({ {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 a1 = boost::make_shared({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 a1 = boost::make_shared(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 a1 = boost::make_shared({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(); +} diff --git a/test/make_shared_arrays_init_test.cpp b/test/make_shared_arrays_init_test.cpp new file mode 100644 index 0000000..1646d5a --- /dev/null +++ b/test/make_shared_arrays_init_test.cpp @@ -0,0 +1,23 @@ +/* + * 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 +#include + +int main() { +#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) && !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) + { + boost::shared_ptr a1 = boost::make_shared({ {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(); +} diff --git a/test/make_shared_arrays_test.cpp b/test/make_shared_arrays_test.cpp index b905a83..e03a13c 100644 --- a/test/make_shared_arrays_test.cpp +++ b/test/make_shared_arrays_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2014 Glen Joseph Fernandes + * Copyright (c) 2012 Glen Joseph Fernandes * glenfe at live dot com * * Distributed under the Boost Software License, @@ -9,40 +9,152 @@ #include #include +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() { -#if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { - boost::shared_ptr a1 = boost::make_shared(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 a1 = boost::make_shared(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::shared_ptr a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared({ 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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 a1 = boost::make_shared({ 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 a1 = boost::make_shared(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 a1 = boost::make_shared(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 - + { + boost::shared_ptr a1 = boost::make_shared_noinit(2); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + } + { + boost::shared_ptr a1 = boost::make_shared_noinit(); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + } + { + boost::shared_ptr a1 = boost::make_shared_noinit(2); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + } + { + boost::shared_ptr a1 = boost::make_shared_noinit(); + BOOST_TEST(a1.get() != 0); + BOOST_TEST(a1.use_count() == 1); + } + BOOST_TEST(type::instances == 0); + { + boost::shared_ptr a1 = boost::make_shared_noinit(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 a1 = boost::make_shared_noinit(); + 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 a1 = boost::make_shared_noinit(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 a1 = boost::make_shared_noinit(); + 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(); }