From 7af503d3bbb0536c5d6e7d862b25cc827fd7f378 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Sun, 8 Nov 2015 00:38:22 -0500 Subject: [PATCH 1/5] Refactor make_unique implementations Before the pending refactor of make_shared/allocate_shared for arrays. --- include/boost/make_unique.hpp | 14 +-- .../boost/smart_ptr/detail/up_if_array.hpp | 26 ----- .../smart_ptr/detail/up_if_not_array.hpp | 31 ----- include/boost/smart_ptr/make_unique.hpp | 108 ++++++++++++++++-- include/boost/smart_ptr/make_unique_array.hpp | 31 ----- .../boost/smart_ptr/make_unique_object.hpp | 45 -------- test/make_unique_args_test.cpp | 22 ++-- test/make_unique_array_noinit_test.cpp | 22 ++-- test/make_unique_array_test.cpp | 22 ++-- test/make_unique_array_throws_test.cpp | 22 ++-- test/make_unique_noinit_test.cpp | 22 ++-- test/make_unique_test.cpp | 22 ++-- test/make_unique_throws_test.cpp | 22 ++-- test/make_unique_value_test.cpp | 22 ++-- 14 files changed, 202 insertions(+), 229 deletions(-) delete mode 100644 include/boost/smart_ptr/detail/up_if_array.hpp delete mode 100644 include/boost/smart_ptr/detail/up_if_not_array.hpp delete mode 100644 include/boost/smart_ptr/make_unique_array.hpp delete mode 100644 include/boost/smart_ptr/make_unique_object.hpp diff --git a/include/boost/make_unique.hpp b/include/boost/make_unique.hpp index c163673..4dc82c3 100644 --- a/include/boost/make_unique.hpp +++ b/include/boost/make_unique.hpp @@ -1,11 +1,11 @@ /* - * Copyright (c) 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) - */ +(c) 2014 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #ifndef BOOST_MAKE_UNIQUE_HPP_INCLUDED #define BOOST_MAKE_UNIQUE_HPP_INCLUDED diff --git a/include/boost/smart_ptr/detail/up_if_array.hpp b/include/boost/smart_ptr/detail/up_if_array.hpp deleted file mode 100644 index 7e62d10..0000000 --- a/include/boost/smart_ptr/detail/up_if_array.hpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 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) - */ -#ifndef BOOST_SMART_PTR_DETAIL_UP_IF_ARRAY_HPP -#define BOOST_SMART_PTR_DETAIL_UP_IF_ARRAY_HPP - -#include - -namespace boost { - namespace detail { - template - struct up_if_array; - - template - struct up_if_array { - typedef std::unique_ptr type; - }; - } -} - -#endif diff --git a/include/boost/smart_ptr/detail/up_if_not_array.hpp b/include/boost/smart_ptr/detail/up_if_not_array.hpp deleted file mode 100644 index fd74f25..0000000 --- a/include/boost/smart_ptr/detail/up_if_not_array.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 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) - */ -#ifndef BOOST_SMART_PTR_DETAIL_UP_IF_NOT_ARRAY_HPP -#define BOOST_SMART_PTR_DETAIL_UP_IF_NOT_ARRAY_HPP - -#include - -namespace boost { - namespace detail { - template - struct up_if_not_array { - typedef std::unique_ptr type; - }; - - template - struct up_if_not_array { - }; - - template - struct up_if_not_array { - }; - } -} - -#endif diff --git a/include/boost/smart_ptr/make_unique.hpp b/include/boost/smart_ptr/make_unique.hpp index 90402e2..f1f4a7c 100644 --- a/include/boost/smart_ptr/make_unique.hpp +++ b/include/boost/smart_ptr/make_unique.hpp @@ -1,15 +1,105 @@ /* - * Copyright (c) 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) - */ +(c) 2014-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP #define BOOST_SMART_PTR_MAKE_UNIQUE_HPP -#include -#include +#include +#include + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +#include +#endif + +namespace boost { +namespace detail { +template +struct up_if_object { + typedef std::unique_ptr type; +}; + +template +struct up_if_object { +}; + +template +struct up_if_object { +}; + +template +struct up_if_array { +}; + +template +struct up_if_array { + typedef std::unique_ptr type; +}; + +template +struct up_value { + typedef T&& type; +}; + +template +struct up_element { +}; + +template +struct up_element { + typedef T type; +}; +} /* detail */ + +template +inline typename detail::up_if_object::type +make_unique() +{ + return std::unique_ptr(new T()); +} + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +template +inline typename detail::up_if_object::type +make_unique(Args&&... args) +{ + return std::unique_ptr(new T(std::forward(args)...)); +} +#endif + +template +inline typename detail::up_if_object::type +make_unique(typename detail::up_value::type value) +{ + return std::unique_ptr(new T(std::move(value))); +} + +template +inline typename detail::up_if_object::type +make_unique_noinit() +{ + return std::unique_ptr(new T); +} + +template +inline typename detail::up_if_array::type +make_unique(std::size_t n) +{ + return std::unique_ptr(new + typename detail::up_element::type[n]()); +} + +template +inline typename detail::up_if_array::type +make_unique_noinit(std::size_t n) +{ + return std::unique_ptr(new + typename detail::up_element::type[n]); +} +} /* boost */ #endif diff --git a/include/boost/smart_ptr/make_unique_array.hpp b/include/boost/smart_ptr/make_unique_array.hpp deleted file mode 100644 index eb0528e..0000000 --- a/include/boost/smart_ptr/make_unique_array.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 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) - */ -#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_ARRAY_HPP -#define BOOST_SMART_PTR_MAKE_UNIQUE_ARRAY_HPP - -#include -#include - -namespace boost { - template - inline typename boost::detail::up_if_array::type - make_unique(std::size_t size) { - typedef typename boost::detail::array_inner::type U; - return std::unique_ptr(new U[size]()); - } - - template - inline typename boost::detail::up_if_array::type - make_unique_noinit(std::size_t size) { - typedef typename boost::detail::array_inner::type U; - return std::unique_ptr(new U[size]); - } -} - -#endif diff --git a/include/boost/smart_ptr/make_unique_object.hpp b/include/boost/smart_ptr/make_unique_object.hpp deleted file mode 100644 index 9e6108a..0000000 --- a/include/boost/smart_ptr/make_unique_object.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 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) - */ -#ifndef BOOST_SMART_PTR_MAKE_UNIQUE_OBJECT_HPP -#define BOOST_SMART_PTR_MAKE_UNIQUE_OBJECT_HPP - -#include -#include -#include -#include - -namespace boost { - template - inline typename boost::detail::up_if_not_array::type - make_unique() { - return std::unique_ptr(new T()); - } - -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - template - inline typename boost::detail::up_if_not_array::type - make_unique(Args&&... args) { - return std::unique_ptr(new T(std::forward(args)...)); - } -#endif - - template - inline typename boost::detail::up_if_not_array::type - make_unique(typename add_rvalue_reference::type value) { - return std::unique_ptr(new T(std::move(value))); - } - - template - inline typename boost::detail::up_if_not_array::type - make_unique_noinit() { - return std::unique_ptr(new T); - } -} - -#endif diff --git a/test/make_unique_args_test.cpp b/test/make_unique_args_test.cpp index 6c13d41..7231a8d 100644 --- a/test/make_unique_args_test.cpp +++ b/test/make_unique_args_test.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) 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) - */ +(c) 2014 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) #include -#include +#include class type { public: @@ -41,7 +41,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ BOOST_TEST(type::instances == 0); { std::unique_ptr a1 = boost::make_unique(); @@ -139,7 +140,8 @@ int main() { } #else -int main() { +int main() +{ return 0; } diff --git a/test/make_unique_array_noinit_test.cpp b/test/make_unique_array_noinit_test.cpp index edaa67f..675c470 100644 --- a/test/make_unique_array_noinit_test.cpp +++ b/test/make_unique_array_noinit_test.cpp @@ -1,15 +1,15 @@ /* - * 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) - */ +(c) 2014 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) #include -#include +#include class type { public: @@ -30,7 +30,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { std::unique_ptr a1 = boost::make_unique_noinit(3); BOOST_TEST(a1.get() != 0); @@ -81,7 +82,8 @@ int main() { } #else -int main() { +int main() +{ return 0; } diff --git a/test/make_unique_array_test.cpp b/test/make_unique_array_test.cpp index 8e5ea79..af0a065 100644 --- a/test/make_unique_array_test.cpp +++ b/test/make_unique_array_test.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) 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) - */ +(c) 2014 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) #include -#include +#include class type { public: @@ -30,7 +30,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { std::unique_ptr a1 = boost::make_unique(3); BOOST_TEST(a1.get() != 0); @@ -105,7 +106,8 @@ int main() { } #else -int main() { +int main() +{ return 0; } diff --git a/test/make_unique_array_throws_test.cpp b/test/make_unique_array_throws_test.cpp index 3efbc2a..e38b145 100644 --- a/test/make_unique_array_throws_test.cpp +++ b/test/make_unique_array_throws_test.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) 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) - */ +(c) 2014 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) #include -#include +#include class type { public: @@ -33,7 +33,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ BOOST_TEST(type::instances == 0); try { boost::make_unique(6); @@ -70,7 +71,8 @@ int main() { } #else -int main() { +int main() +{ return 0; } diff --git a/test/make_unique_noinit_test.cpp b/test/make_unique_noinit_test.cpp index 1ef0daa..3de787c 100644 --- a/test/make_unique_noinit_test.cpp +++ b/test/make_unique_noinit_test.cpp @@ -1,15 +1,15 @@ /* - * 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) - */ +(c) 2014 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) #include -#include +#include class type { public: @@ -30,7 +30,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { std::unique_ptr a1 = boost::make_unique_noinit(); BOOST_TEST(a1.get() != 0); @@ -58,7 +59,8 @@ int main() { } #else -int main() { +int main() +{ return 0; } diff --git a/test/make_unique_test.cpp b/test/make_unique_test.cpp index ab13c33..a2c6b99 100644 --- a/test/make_unique_test.cpp +++ b/test/make_unique_test.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) 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) - */ +(c) 2014 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) #include -#include +#include class type { public: @@ -30,7 +30,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { std::unique_ptr a1 = boost::make_unique(); BOOST_TEST(a1.get() != 0); @@ -65,7 +66,8 @@ int main() { } #else -int main() { +int main() +{ return 0; } diff --git a/test/make_unique_throws_test.cpp b/test/make_unique_throws_test.cpp index 9594c90..c8fdcc8 100644 --- a/test/make_unique_throws_test.cpp +++ b/test/make_unique_throws_test.cpp @@ -1,15 +1,15 @@ /* - * Copyright (c) 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) - */ +(c) 2014 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) #include -#include +#include class type { public: @@ -33,7 +33,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ BOOST_TEST(type::instances == 0); try { boost::make_unique(); @@ -46,7 +47,8 @@ int main() { } #else -int main() { +int main() +{ return 0; } diff --git a/test/make_unique_value_test.cpp b/test/make_unique_value_test.cpp index 03cdf47..4b34af8 100644 --- a/test/make_unique_value_test.cpp +++ b/test/make_unique_value_test.cpp @@ -1,22 +1,23 @@ /* - * Copyright (c) 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) - */ +(c) 2014 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) #include -#include +#include struct type { int x; int y; }; -int main() { +int main() +{ { std::unique_ptr a1 = boost::make_unique(); BOOST_TEST(a1.get() != 0); @@ -51,7 +52,8 @@ int main() { } #else -int main() { +int main() +{ return 0; } From 38b6334e36831092e42a1553a297aa7cec106bcf Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Mon, 9 Nov 2015 22:35:34 -0500 Subject: [PATCH 2/5] Update unit tests for make_shared/allocate_shared for arrays Before pending refactor of make_shared and allocate_shared for arrays. --- test/allocate_shared_array_construct_test.cpp | 111 ++++++------------ test/allocate_shared_array_esft_test.cpp | 26 ++-- test/allocate_shared_array_noinit_test.cpp | 48 ++------ test/allocate_shared_array_test.cpp | 48 ++------ test/allocate_shared_array_throws_test.cpp | 40 ++----- test/allocate_shared_array_value_test.cpp | 25 ++-- test/allocate_shared_arrays_test.cpp | 25 ++-- test/make_shared_array_esft_test.cpp | 26 ++-- test/make_shared_array_noinit_test.cpp | 48 ++------ test/make_shared_array_test.cpp | 48 ++------ test/make_shared_array_throws_test.cpp | 38 ++---- test/make_shared_array_value_test.cpp | 25 ++-- test/make_shared_arrays_test.cpp | 11 +- 13 files changed, 163 insertions(+), 356 deletions(-) diff --git a/test/allocate_shared_array_construct_test.cpp b/test/allocate_shared_array_construct_test.cpp index fe9fe3f..0228275 100644 --- a/test/allocate_shared_array_construct_test.cpp +++ b/test/allocate_shared_array_construct_test.cpp @@ -1,43 +1,38 @@ /* - * 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 -#if !defined(BOOST_NO_CXX11_ALLOCATOR) -#include +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include + +struct tag { }; template class creator { public: typedef T value_type; - creator() { } - template creator(const creator&) { } - T* allocate(std::size_t size) { - void* p1 = ::operator new(size * sizeof(T)); - return static_cast(p1); + void* p = ::operator new(size * sizeof(T)); + return static_cast(p); } - void deallocate(T* memory, std::size_t) { - void* p1 = memory; - ::operator delete(p1); + void* p = memory; + ::operator delete(p); } - template void construct(U* memory) { - void* p1 = memory; - ::new(p1) U(); + void* p = memory; + ::new(p) U(tag()); } - template void destroy(U* memory) { memory->~U(); @@ -45,116 +40,88 @@ public: }; class type { - friend class creator; - public: static unsigned int instances; - static const type object; - -protected: - explicit type() { + explicit type(tag) { instances++; } - type(const type&) { instances++; } - ~type() { instances--; } }; -unsigned int type::instances; -const type type::object; +unsigned int type::instances = 0; -int main() { - BOOST_TEST(type::instances == 1); +int main() +{ +#if !defined(BOOST_NO_CXX11_ALLOCATOR) { boost::shared_ptr a1 = boost::allocate_shared(creator(), 3); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1.get() != 0); - BOOST_TEST(type::instances == 4); + BOOST_TEST(type::instances == 3); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator()); BOOST_TEST(a1.use_count() == 1); BOOST_TEST(a1.get() != 0); - BOOST_TEST(type::instances == 4); + BOOST_TEST(type::instances == 3); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator(), 2); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 5); + BOOST_TEST(type::instances == 4); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator()); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 5); + BOOST_TEST(type::instances == 4); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator(), 3); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 4); + BOOST_TEST(type::instances == 3); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator()); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 4); + BOOST_TEST(type::instances == 3); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator(), 2); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 5); + BOOST_TEST(type::instances == 4); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 1); { boost::shared_ptr a1 = boost::allocate_shared(creator()); BOOST_TEST(a1.get() != 0); BOOST_TEST(a1.use_count() == 1); - BOOST_TEST(type::instances == 5); + BOOST_TEST(type::instances == 4); a1.reset(); - BOOST_TEST(type::instances == 1); + BOOST_TEST(type::instances == 0); } - +#endif return boost::report_errors(); } -#else - -int main() { - return 0; -} - -#endif diff --git a/test/allocate_shared_array_esft_test.cpp b/test/allocate_shared_array_esft_test.cpp index b342366..30edfff 100644 --- a/test/allocate_shared_array_esft_test.cpp +++ b/test/allocate_shared_array_esft_test.cpp @@ -1,28 +1,25 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include #include +#include 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&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); @@ -41,7 +39,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 +49,5 @@ int main() { BOOST_TEST(type::instances == 3); } } - return boost::report_errors(); } diff --git a/test/allocate_shared_array_noinit_test.cpp b/test/allocate_shared_array_noinit_test.cpp index 6c8ff3d..83b48ec 100644 --- a/test/allocate_shared_array_noinit_test.cpp +++ b/test/allocate_shared_array_noinit_test.cpp @@ -1,28 +1,25 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +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&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); int* a2 = a1.get(); @@ -38,7 +36,6 @@ int main() { 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(); @@ -46,19 +43,16 @@ int main() { 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(); @@ -66,7 +60,6 @@ int main() { 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(); @@ -74,20 +67,16 @@ int main() { 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(); @@ -99,8 +88,6 @@ int main() { 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(); @@ -112,8 +99,6 @@ int main() { 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); @@ -122,8 +107,6 @@ int main() { 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); @@ -132,8 +115,6 @@ int main() { 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(); @@ -144,8 +125,6 @@ int main() { 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(); @@ -156,8 +135,6 @@ int main() { 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); @@ -166,8 +143,6 @@ int main() { 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); @@ -176,6 +151,5 @@ int main() { 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..c5a5714 100644 --- a/test/allocate_shared_array_test.cpp +++ b/test/allocate_shared_array_test.cpp @@ -1,28 +1,25 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +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&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); int* a2 = a1.get(); @@ -41,7 +39,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(); @@ -52,7 +49,6 @@ int main() { 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); @@ -62,7 +58,6 @@ int main() { 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); @@ -72,7 +67,6 @@ int main() { 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,7 +77,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(); @@ -94,7 +87,6 @@ int main() { 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); @@ -104,7 +96,6 @@ int main() { 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); @@ -114,8 +105,6 @@ int main() { 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); type* a2 = a1.get(); @@ -127,8 +116,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(); @@ -140,8 +127,6 @@ 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); @@ -150,8 +135,6 @@ int main() { 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); @@ -160,8 +143,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); const type* a2 = a1.get(); @@ -172,8 +153,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::allocate_shared(std::allocator()); const type* a2 = a1.get(); @@ -184,8 +163,6 @@ 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); @@ -194,8 +171,6 @@ int main() { 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); @@ -204,6 +179,5 @@ int main() { 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..e14d984 100644 --- a/test/allocate_shared_array_throws_test.cpp +++ b/test/allocate_shared_array_throws_test.cpp @@ -1,29 +1,26 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include 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&); @@ -31,70 +28,55 @@ private: unsigned int type::instances = 0; -int main() { - BOOST_TEST(type::instances == 0); +int main() +{ try { boost::allocate_shared(std::allocator(), 6); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared(std::allocator(), 3); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared(std::allocator()); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared(std::allocator()); BOOST_ERROR("allocate_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::allocate_shared_noinit(std::allocator(), 6); 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(), 3); 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); } - - 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 index c1b8b7c..c6f08f9 100644 --- a/test/allocate_shared_array_value_test.cpp +++ b/test/allocate_shared_array_value_test.cpp @@ -1,15 +1,16 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + -int main() { +Distributed under the Boost Software +License, Version 1.0. +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); @@ -17,7 +18,6 @@ int main() { 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); @@ -25,7 +25,6 @@ int main() { 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); @@ -33,7 +32,6 @@ int main() { 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); @@ -41,6 +39,5 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - return boost::report_errors(); } diff --git a/test/allocate_shared_arrays_test.cpp b/test/allocate_shared_arrays_test.cpp index 9dfc866..7c45e72 100644 --- a/test/allocate_shared_arrays_test.cpp +++ b/test/allocate_shared_arrays_test.cpp @@ -1,15 +1,16 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + -int main() { +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include +#include + +int main() +{ #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, {0, 1}); @@ -18,7 +19,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -26,7 +26,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 2, { 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -34,7 +33,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), { 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -43,6 +41,5 @@ int main() { BOOST_TEST(a1[1][1] == 1); } #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..8429919 100644 --- a/test/make_shared_array_esft_test.cpp +++ b/test/make_shared_array_esft_test.cpp @@ -1,28 +1,25 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ +#include #include -#include +#include 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&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(3); @@ -41,7 +39,6 @@ int main() { BOOST_TEST(type::instances == 3); } } - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(3); @@ -52,6 +49,5 @@ int main() { BOOST_TEST(type::instances == 3); } } - return boost::report_errors(); } diff --git a/test/make_shared_array_noinit_test.cpp b/test/make_shared_array_noinit_test.cpp index 98bd450..4942569 100644 --- a/test/make_shared_array_noinit_test.cpp +++ b/test/make_shared_array_noinit_test.cpp @@ -1,28 +1,25 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +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&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { boost::shared_ptr a1 = boost::make_shared_noinit(3); int* a2 = a1.get(); @@ -38,7 +36,6 @@ int main() { 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(); @@ -46,19 +43,16 @@ int main() { 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(); @@ -66,7 +60,6 @@ int main() { 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(); @@ -74,20 +67,16 @@ int main() { 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(); @@ -99,8 +88,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared_noinit(); type* a2 = a1.get(); @@ -112,8 +99,6 @@ int main() { 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); @@ -122,8 +107,6 @@ int main() { 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); @@ -132,8 +115,6 @@ int main() { 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(); @@ -144,8 +125,6 @@ int main() { 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(); @@ -156,8 +135,6 @@ int main() { 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); @@ -166,8 +143,6 @@ int main() { 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); @@ -176,6 +151,5 @@ int main() { 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..de74198 100644 --- a/test/make_shared_array_test.cpp +++ b/test/make_shared_array_test.cpp @@ -1,28 +1,25 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +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&); @@ -30,7 +27,8 @@ private: unsigned int type::instances = 0; -int main() { +int main() +{ { boost::shared_ptr a1 = boost::make_shared(3); int* a2 = a1.get(); @@ -41,7 +39,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::make_shared(); int* a2 = a1.get(); @@ -52,7 +49,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::make_shared(2); BOOST_TEST(a1.get() != 0); @@ -62,7 +58,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - { boost::shared_ptr a1 = boost::make_shared(); BOOST_TEST(a1.get() != 0); @@ -72,7 +67,6 @@ int main() { 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,7 +77,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(); @@ -94,7 +87,6 @@ int main() { BOOST_TEST(a1[1] == 0); BOOST_TEST(a1[2] == 0); } - { boost::shared_ptr a1 = boost::make_shared(2); BOOST_TEST(a1.get() != 0); @@ -104,7 +96,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 0); } - { boost::shared_ptr a1 = boost::make_shared(); BOOST_TEST(a1.get() != 0); @@ -114,8 +105,6 @@ int main() { 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); type* a2 = a1.get(); @@ -127,8 +116,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(); @@ -140,8 +127,6 @@ 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); @@ -150,8 +135,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(); BOOST_TEST(a1.get() != 0); @@ -160,8 +143,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(3); const type* a2 = a1.get(); @@ -172,8 +153,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(); const type* a2 = a1.get(); @@ -184,8 +163,6 @@ 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); @@ -194,8 +171,6 @@ int main() { a1.reset(); BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); { boost::shared_ptr a1 = boost::make_shared(); BOOST_TEST(a1.get() != 0); @@ -204,6 +179,5 @@ int main() { 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..56c7372 100644 --- a/test/make_shared_array_throws_test.cpp +++ b/test/make_shared_array_throws_test.cpp @@ -1,29 +1,26 @@ /* - * 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) - */ +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include -#include +#include 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&); @@ -31,70 +28,55 @@ private: unsigned int type::instances = 0; -int main() { - BOOST_TEST(type::instances == 0); +int main() +{ try { boost::make_shared(6); BOOST_ERROR("make_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::make_shared(3); BOOST_ERROR("make_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::make_shared(); BOOST_ERROR("make_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::make_shared(); BOOST_ERROR("make_shared did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::make_shared_noinit(6); BOOST_ERROR("make_shared_noinit did not throw"); } catch (...) { BOOST_TEST(type::instances == 0); } - - BOOST_TEST(type::instances == 0); try { boost::make_shared_noinit(3); 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); } - - 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 index f042ede..185605d 100644 --- a/test/make_shared_array_value_test.cpp +++ b/test/make_shared_array_value_test.cpp @@ -1,15 +1,16 @@ /* - * 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 +(c) 2012-2015 Glen Joseph Fernandes + -int main() { +Distributed under the Boost Software +License, Version 1.0. +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); @@ -17,7 +18,6 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - { boost::shared_ptr a1 = boost::make_shared(1); BOOST_TEST(a1[0] == 1); @@ -25,7 +25,6 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - { boost::shared_ptr a1 = boost::make_shared(4, 1); BOOST_TEST(a1[0] == 1); @@ -33,7 +32,6 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - { boost::shared_ptr a1 = boost::make_shared(1); BOOST_TEST(a1[0] == 1); @@ -41,6 +39,5 @@ int main() { BOOST_TEST(a1[2] == 1); BOOST_TEST(a1[3] == 1); } - return boost::report_errors(); } diff --git a/test/make_shared_arrays_test.cpp b/test/make_shared_arrays_test.cpp index b905a83..6c02db7 100644 --- a/test/make_shared_arrays_test.cpp +++ b/test/make_shared_arrays_test.cpp @@ -6,10 +6,11 @@ * Version 1.0. (See accompanying file LICENSE_1_0.txt * or copy at http://boost.org/LICENSE_1_0.txt) */ -#include -#include +#include +#include -int main() { +int main() +{ #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { boost::shared_ptr a1 = boost::make_shared(2, {0, 1}); @@ -18,7 +19,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::make_shared({ 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -26,7 +26,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::make_shared(2, { 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -34,7 +33,6 @@ int main() { BOOST_TEST(a1[1][0] == 0); BOOST_TEST(a1[1][1] == 1); } - { boost::shared_ptr a1 = boost::make_shared({ 0, 1 }); BOOST_TEST(a1[0][0] == 0); @@ -43,6 +41,5 @@ int main() { BOOST_TEST(a1[1][1] == 1); } #endif - return boost::report_errors(); } From 7a7ac4512edf952c4f1ba45d1da3d5d28ef5343e Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Wed, 11 Nov 2015 01:26:15 -0500 Subject: [PATCH 3/5] Fix formatting in headers and tests --- include/boost/smart_ptr/make_unique.hpp | 27 +++++++++---------------- test/make_shared_arrays_test.cpp | 14 ++++++------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/include/boost/smart_ptr/make_unique.hpp b/include/boost/smart_ptr/make_unique.hpp index f1f4a7c..48191b7 100644 --- a/include/boost/smart_ptr/make_unique.hpp +++ b/include/boost/smart_ptr/make_unique.hpp @@ -24,16 +24,13 @@ struct up_if_object { }; template -struct up_if_object { -}; +struct up_if_object { }; template -struct up_if_object { -}; +struct up_if_object { }; template -struct up_if_array { -}; +struct up_if_array { }; template struct up_if_array { @@ -46,8 +43,7 @@ struct up_value { }; template -struct up_element { -}; +struct up_element { }; template struct up_element { @@ -56,8 +52,7 @@ struct up_element { } /* detail */ template -inline typename detail::up_if_object::type -make_unique() +inline typename detail::up_if_object::type make_unique() { return std::unique_ptr(new T()); } @@ -65,7 +60,7 @@ make_unique() #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template inline typename detail::up_if_object::type -make_unique(Args&&... args) + make_unique(Args&&... args) { return std::unique_ptr(new T(std::forward(args)...)); } @@ -73,21 +68,19 @@ make_unique(Args&&... args) template inline typename detail::up_if_object::type -make_unique(typename detail::up_value::type value) + make_unique(typename detail::up_value::type value) { return std::unique_ptr(new T(std::move(value))); } template -inline typename detail::up_if_object::type -make_unique_noinit() +inline typename detail::up_if_object::type make_unique_noinit() { return std::unique_ptr(new T); } template -inline typename detail::up_if_array::type -make_unique(std::size_t n) +inline typename detail::up_if_array::type make_unique(std::size_t n) { return std::unique_ptr(new typename detail::up_element::type[n]()); @@ -95,7 +88,7 @@ make_unique(std::size_t n) template inline typename detail::up_if_array::type -make_unique_noinit(std::size_t n) + make_unique_noinit(std::size_t n) { return std::unique_ptr(new typename detail::up_element::type[n]); diff --git a/test/make_shared_arrays_test.cpp b/test/make_shared_arrays_test.cpp index 6c02db7..7cd067f 100644 --- a/test/make_shared_arrays_test.cpp +++ b/test/make_shared_arrays_test.cpp @@ -1,11 +1,11 @@ /* - * 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) - */ +(c) 2012-2015 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ #include #include From 4473bf8ec2a1a124713dcc4183d6c120f5191305 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 15 Dec 2015 19:13:20 +0200 Subject: [PATCH 4/5] Fix hash support for shared_ptr, --- include/boost/smart_ptr/shared_ptr.hpp | 2 +- test/Jamfile.v2 | 3 +++ test/sp_hash_test2.cpp | 34 ++++++++++++++++++++++++++ test/sp_hash_test3.cpp | 34 ++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 test/sp_hash_test2.cpp create mode 100644 test/sp_hash_test3.cpp diff --git a/include/boost/smart_ptr/shared_ptr.hpp b/include/boost/smart_ptr/shared_ptr.hpp index 47bc33d..bcefda8 100644 --- a/include/boost/smart_ptr/shared_ptr.hpp +++ b/include/boost/smart_ptr/shared_ptr.hpp @@ -1065,7 +1065,7 @@ template< class T > struct hash; template< class T > std::size_t hash_value( boost::shared_ptr const & p ) BOOST_NOEXCEPT { - return boost::hash< T* >()( p.get() ); + return boost::hash< typename boost::shared_ptr::element_type* >()( p.get() ); } } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 62fab50..963eebc 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -181,5 +181,8 @@ import testing ; [ run weak_from_this_test2.cpp ] [ run sp_bml_unique_ptr_test.cpp ] + + [ run sp_hash_test2.cpp ] + [ run sp_hash_test3.cpp ] ; } diff --git a/test/sp_hash_test2.cpp b/test/sp_hash_test2.cpp new file mode 100644 index 0000000..c1cbf70 --- /dev/null +++ b/test/sp_hash_test2.cpp @@ -0,0 +1,34 @@ +// +// sp_hash_test2.cpp +// +// Copyright 2011, 2015 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 + +int main() +{ + boost::hash< boost::shared_ptr > hasher; + + boost::shared_ptr< int[] > p1, p2( p1 ), p3( new int[1] ), p4( p3 ), p5( new int[1] ); + + BOOST_TEST_EQ( p1, p2 ); + BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) ); + + BOOST_TEST_NE( p1, p3 ); + BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) ); + + BOOST_TEST_EQ( p3, p4 ); + BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) ); + + BOOST_TEST_NE( p3, p5 ); + BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) ); + + return boost::report_errors(); +} diff --git a/test/sp_hash_test3.cpp b/test/sp_hash_test3.cpp new file mode 100644 index 0000000..4d4acad --- /dev/null +++ b/test/sp_hash_test3.cpp @@ -0,0 +1,34 @@ +// +// sp_hash_test3.cpp +// +// Copyright 2011, 2015 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 + +int main() +{ + boost::hash< boost::shared_ptr > hasher; + + boost::shared_ptr< int[1] > p1, p2( p1 ), p3( new int[1] ), p4( p3 ), p5( new int[1] ); + + BOOST_TEST_EQ( p1, p2 ); + BOOST_TEST_EQ( hasher( p1 ), hasher( p2 ) ); + + BOOST_TEST_NE( p1, p3 ); + BOOST_TEST_NE( hasher( p1 ), hasher( p3 ) ); + + BOOST_TEST_EQ( p3, p4 ); + BOOST_TEST_EQ( hasher( p3 ), hasher( p4 ) ); + + BOOST_TEST_NE( p3, p5 ); + BOOST_TEST_NE( hasher( p3 ), hasher( p5 ) ); + + return boost::report_errors(); +} From 427124543b1b6d5260304ef731b2b331d77c178d Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Fri, 19 Feb 2016 08:09:25 -0500 Subject: [PATCH 5/5] Use remove_reference in make_unique implementation --- include/boost/smart_ptr/make_unique.hpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/include/boost/smart_ptr/make_unique.hpp b/include/boost/smart_ptr/make_unique.hpp index 48191b7..d054e3d 100644 --- a/include/boost/smart_ptr/make_unique.hpp +++ b/include/boost/smart_ptr/make_unique.hpp @@ -11,10 +11,7 @@ http://boost.org/LICENSE_1_0.txt #include #include - -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) #include -#endif namespace boost { namespace detail { @@ -38,8 +35,18 @@ struct up_if_array { }; template -struct up_value { - typedef T&& type; +struct up_remove_reference { + typedef T type; +}; + +template +struct up_remove_reference { + typedef T type; +}; + +template +struct up_remove_reference { + typedef T type; }; template @@ -68,7 +75,7 @@ inline typename detail::up_if_object::type template inline typename detail::up_if_object::type - make_unique(typename detail::up_value::type value) + make_unique(typename detail::up_remove_reference::type&& value) { return std::unique_ptr(new T(std::move(value))); }