diff --git a/include/boost/smart_ptr/make_unique.hpp b/include/boost/smart_ptr/make_unique.hpp index d054e3d..eed5033 100644 --- a/include/boost/smart_ptr/make_unique.hpp +++ b/include/boost/smart_ptr/make_unique.hpp @@ -1,10 +1,9 @@ /* -(c) 2014-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_SMART_PTR_MAKE_UNIQUE_HPP #define BOOST_SMART_PTR_MAKE_UNIQUE_HPP @@ -15,6 +14,7 @@ http://boost.org/LICENSE_1_0.txt namespace boost { namespace detail { + template struct up_if_object { typedef std::unique_ptr type; @@ -56,10 +56,12 @@ template struct up_element { typedef T type; }; + } /* 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()); } @@ -67,7 +69,7 @@ inline typename detail::up_if_object::type 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)...)); } @@ -75,31 +77,34 @@ inline typename detail::up_if_object::type template inline typename detail::up_if_object::type - make_unique(typename detail::up_remove_reference::type&& value) +make_unique(typename detail::up_remove_reference::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 size) { - return std::unique_ptr(new - typename detail::up_element::type[n]()); + return std::unique_ptr(new typename + detail::up_element::type[size]()); } template inline typename detail::up_if_array::type - make_unique_noinit(std::size_t n) +make_unique_noinit(std::size_t size) { - return std::unique_ptr(new - typename detail::up_element::type[n]); + return std::unique_ptr(new typename + detail::up_element::type[size]); } + } /* boost */ #endif diff --git a/make_unique.html b/make_unique.html index 5b414e8..b649245 100644 --- a/make_unique.html +++ b/make_unique.html @@ -21,10 +21,8 @@ template<class U> // U is not array unique_ptr<U> make_unique(); -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) template<class U, class... Args> // U is not array unique_ptr<U> make_unique(Args&&... args); -#endif template<class U> // U is not array unique_ptr<U> make_unique(U&& value); @@ -40,9 +38,9 @@ }

Common Requirements

template<class U>
-    unique_ptr<U> make_unique(args);
-template<class U>
-    unique_ptr<U> make_unique_noinit(args);
+unique_ptr<U> make_unique(args); +
template<class U>
+unique_ptr<U> make_unique_noinit(args);

Effects: Allocates memory for an object of type U (or T[size] when U is T[], @@ -82,8 +80,8 @@ unique_ptr<U> make_unique(Args&&... args); resolution when U is not an array type.

Examples:

-
unique_ptr<float> p1 = boost::make_unique<float>();
-unique_ptr<point> p2 = boost::make_unique<point>(x, y);
+
unique_ptr<float> p1 = boost::make_unique<float>();
+
unique_ptr<point> p2 = boost::make_unique<point>(x, y);
template<class U>
@@ -95,8 +93,8 @@ unique_ptr<U> make_unique(U&& value);
resolution when U is not an array type.

Examples:

-
unique_ptr<string> p1 = boost::make_unique<string>({'a', 'b'});
-unique_ptr<point> p2 = boost::make_unique<point>({-10, 25});
+
unique_ptr<string> p1 = boost::make_unique<string>({'a', 'b'});
+
unique_ptr<point> p2 = boost::make_unique<point>({-10, 25});
template<class U>
@@ -108,8 +106,8 @@ unique_ptr<U> make_unique(size_t size);
resolution when U is of the form T[].

Examples:

-
unique_ptr<double[]> p1 = boost::make_unique<double[]>(4);
-unique_ptr<int[][2]> p2 = boost::make_unique<int[][2]>(2);
+
unique_ptr<double[]> p1 = boost::make_unique<double[]>(4);
+
unique_ptr<int[][2]> p2 = boost::make_unique<int[][2]>(2);
template<class U>
@@ -121,8 +119,8 @@ unique_ptr<U> make_unique_noinit();
resolution when U is not an array type.

Examples:

-
unique_ptr<float> p1 = boost::make_unique_noinit<float>();
-unique_ptr<point> p2 = boost::make_unique_noinit<point>();
+
unique_ptr<float> p1 = boost::make_unique_noinit<float>();
+
unique_ptr<point> p2 = boost::make_unique_noinit<point>();
template<class U>
@@ -134,8 +132,8 @@ unique_ptr<U> make_unique_noinit(size_t size);
resolution when U is of the form T[].

Examples:

-
unique_ptr<double[]> p1 = boost::make_unique_noinit<double[]>(4);
-unique_ptr<int[][2]> p2 = boost::make_unique_noinit<int[][2]>(2);
+
unique_ptr<double[]> p1 = boost::make_unique_noinit<double[]>(4);
+
unique_ptr<int[][2]> p2 = boost::make_unique_noinit<int[][2]>(2);

History

diff --git a/test/make_unique_args_test.cpp b/test/make_unique_args_test.cpp index 7231a8d..6e46612 100644 --- a/test/make_unique_args_test.cpp +++ b/test/make_unique_args_test.cpp @@ -1,148 +1,155 @@ /* -(c) 2014 Glen Joseph Fernandes - +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) -#include +#include #include class type { public: - static unsigned int instances; + static unsigned instances; - explicit type(int v1 = 0, - int v2 = 0, - int v3 = 0, - int v4 = 0, - int v5 = 0, - int v6 = 0, - int v7 = 0, - int v8 = 0, - int v9 = 0) - : sum(v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9) { - instances++; + type(int v1 = 0, + int v2 = 0, + int v3 = 0, + int v4 = 0, + int v5 = 0, + int v6 = 0, + int v7 = 0, + int v8 = 0, + int v9 = 0) + : sum_(v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9) { + ++instances; } ~type() { - instances--; + --instances; } - const int sum; + int sum() const { + return sum_; + } private: + int sum_; + type(const type&); type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique(); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = boost::make_unique(); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 0); - a1.reset(); + BOOST_TEST(result->sum() == 0); + result.reset(); BOOST_TEST(type::instances == 0); } -#if !defined( BOOST_NO_CXX11_VARIADIC_TEMPLATES ) +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) { - std::unique_ptr a1 = boost::make_unique(1); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = boost::make_unique(1); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 1); - a1.reset(); + BOOST_TEST(result->sum() == 1); + result.reset(); BOOST_TEST(type::instances == 0); } { - std::unique_ptr a1 = boost::make_unique(1, 2); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = boost::make_unique(1, 2); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 1 + 2); - a1.reset(); + BOOST_TEST(result->sum() == 1 + 2); + result.reset(); BOOST_TEST(type::instances == 0); } { - std::unique_ptr a1 = boost::make_unique(1, 2, 3); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(1, 2, 3); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 1 + 2 + 3); - a1.reset(); + BOOST_TEST(result->sum() == 1 + 2 + 3); + result.reset(); BOOST_TEST(type::instances == 0); } { - std::unique_ptr a1 = boost::make_unique(1, 2, 3, 4); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(1, 2, 3, 4); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 1 + 2 + 3 + 4); - a1.reset(); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4); + result.reset(); BOOST_TEST(type::instances == 0); } { - std::unique_ptr a1 = boost::make_unique(1, 2, 3, 4, 5); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(1, 2, 3, 4, 5); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5); - a1.reset(); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5); + result.reset(); BOOST_TEST(type::instances == 0); } { - std::unique_ptr a1 = boost::make_unique(1, 2, 3, 4, 5, 6); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(1, 2, 3, 4, 5, 6); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6); - a1.reset(); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6); + result.reset(); BOOST_TEST(type::instances == 0); } { - std::unique_ptr a1 = boost::make_unique(1, 2, 3, 4, 5, 6, 7); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(1, 2, 3, 4, 5, 6, 7); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7); - a1.reset(); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7); + result.reset(); BOOST_TEST(type::instances == 0); } { - std::unique_ptr a1 = boost::make_unique(1, 2, 3, 4, 5, 6, 7, 8); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(1, 2, 3, 4, 5, 6, 7, 8); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8); - a1.reset(); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8); + result.reset(); BOOST_TEST(type::instances == 0); } { - std::unique_ptr a1 = boost::make_unique(1, 2, 3, 4, 5, 6, 7, 8, 9); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(1, 2, 3, 4, 5, 6, 7, 8, 9); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - BOOST_TEST(a1->sum == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9); - a1.reset(); + BOOST_TEST(result->sum() == 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9); + result.reset(); BOOST_TEST(type::instances == 0); } #endif - return boost::report_errors(); } #else - int main() { return 0; } - #endif diff --git a/test/make_unique_array_noinit_test.cpp b/test/make_unique_array_noinit_test.cpp index 675c470..44ac66e 100644 --- a/test/make_unique_array_noinit_test.cpp +++ b/test/make_unique_array_noinit_test.cpp @@ -1,10 +1,9 @@ /* -(c) 2014 Glen Joseph Fernandes - +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) @@ -13,14 +12,14 @@ http://boost.org/LICENSE_1_0.txt class type { public: - static unsigned int instances; + static unsigned instances; - explicit type() { - instances++; + type() { + ++instances; } ~type() { - instances--; + --instances; } private: @@ -28,63 +27,61 @@ private: type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { { - std::unique_ptr a1 = boost::make_unique_noinit(3); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique_noinit(3); + BOOST_TEST(result.get() != 0); } - { - std::unique_ptr a1 = boost::make_unique_noinit(2); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique_noinit(2); + BOOST_TEST(result.get() != 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique_noinit(3); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique_noinit(3); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique_noinit(2); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique_noinit(2); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique_noinit(3); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique_noinit(3); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique_noinit(2); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique_noinit(2); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } #else - int main() { return 0; } - #endif diff --git a/test/make_unique_array_test.cpp b/test/make_unique_array_test.cpp index af0a065..447f79d 100644 --- a/test/make_unique_array_test.cpp +++ b/test/make_unique_array_test.cpp @@ -1,10 +1,9 @@ /* -(c) 2014 Glen Joseph Fernandes - +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) @@ -13,14 +12,14 @@ http://boost.org/LICENSE_1_0.txt class type { public: - static unsigned int instances; + static unsigned instances; - explicit type() { - instances++; + type() { + ++instances; } ~type() { - instances--; + --instances; } private: @@ -28,87 +27,84 @@ private: type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { { - std::unique_ptr a1 = boost::make_unique(3); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + std::unique_ptr result = boost::make_unique(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } - { - std::unique_ptr a1 = boost::make_unique(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + std::unique_ptr result = + boost::make_unique(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); } - { - std::unique_ptr a1 = boost::make_unique(3); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1[0] == 0); - BOOST_TEST(a1[1] == 0); - BOOST_TEST(a1[2] == 0); + std::unique_ptr result = + boost::make_unique(3); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0] == 0); + BOOST_TEST(result[1] == 0); + BOOST_TEST(result[2] == 0); } - { - std::unique_ptr a1 = boost::make_unique(2); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1[0][0] == 0); - BOOST_TEST(a1[0][1] == 0); - BOOST_TEST(a1[1][0] == 0); - BOOST_TEST(a1[1][1] == 0); + std::unique_ptr result = + boost::make_unique(2); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result[0][0] == 0); + BOOST_TEST(result[0][1] == 0); + BOOST_TEST(result[1][0] == 0); + BOOST_TEST(result[1][1] == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique(3); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(3); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique(2); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(2); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique(3); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(3); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 3); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique(2); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(2); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 4); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } #else - int main() { return 0; } - #endif diff --git a/test/make_unique_array_throws_test.cpp b/test/make_unique_array_throws_test.cpp index e38b145..df4ab26 100644 --- a/test/make_unique_array_throws_test.cpp +++ b/test/make_unique_array_throws_test.cpp @@ -1,10 +1,9 @@ /* -(c) 2014 Glen Joseph Fernandes - +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) @@ -13,17 +12,17 @@ http://boost.org/LICENSE_1_0.txt class type { public: - static unsigned int instances; + static unsigned instances; - explicit type() { + type() { if (instances == 5) { throw true; } - instances++; + ++instances; } ~type() { - instances--; + --instances; } private: @@ -31,7 +30,7 @@ private: type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { @@ -42,7 +41,6 @@ int main() } catch (...) { BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); try { boost::make_unique(3); @@ -50,7 +48,6 @@ int main() } catch (...) { BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); try { boost::make_unique_noinit(6); @@ -58,7 +55,6 @@ int main() } catch (...) { BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); try { boost::make_unique_noinit(3); @@ -66,14 +62,11 @@ int main() } catch (...) { BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } #else - int main() { return 0; } - #endif diff --git a/test/make_unique_noinit_test.cpp b/test/make_unique_noinit_test.cpp index 3de787c..a7cd828 100644 --- a/test/make_unique_noinit_test.cpp +++ b/test/make_unique_noinit_test.cpp @@ -1,10 +1,9 @@ /* -(c) 2014 Glen Joseph Fernandes - +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) @@ -13,14 +12,14 @@ http://boost.org/LICENSE_1_0.txt class type { public: - static unsigned int instances; + static unsigned instances; - explicit type() { - instances++; + type() { + ++instances; } ~type() { - instances--; + --instances; } private: @@ -28,40 +27,37 @@ private: type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { { - std::unique_ptr a1 = boost::make_unique_noinit(); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = boost::make_unique_noinit(); + BOOST_TEST(result.get() != 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique_noinit(); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique_noinit(); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique_noinit(); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique_noinit(); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } #else - int main() { return 0; } - #endif diff --git a/test/make_unique_test.cpp b/test/make_unique_test.cpp index a2c6b99..74c6033 100644 --- a/test/make_unique_test.cpp +++ b/test/make_unique_test.cpp @@ -1,10 +1,9 @@ /* -(c) 2014 Glen Joseph Fernandes - +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) @@ -13,14 +12,14 @@ http://boost.org/LICENSE_1_0.txt class type { public: - static unsigned int instances; + static unsigned instances; - explicit type() { - instances++; + type() { + ++instances; } ~type() { - instances--; + --instances; } private: @@ -28,47 +27,44 @@ private: type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { { - std::unique_ptr a1 = boost::make_unique(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(*a1 == 0); + std::unique_ptr result = boost::make_unique(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(*result == 0); } - { - std::unique_ptr a1 = boost::make_unique(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(*a1 == 0); + std::unique_ptr result = + boost::make_unique(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(*result == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique(); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - BOOST_TEST(type::instances == 0); { - std::unique_ptr a1 = boost::make_unique(); - BOOST_TEST(a1.get() != 0); + std::unique_ptr result = + boost::make_unique(); + BOOST_TEST(result.get() != 0); BOOST_TEST(type::instances == 1); - a1.reset(); + result.reset(); BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } #else - int main() { return 0; } - #endif diff --git a/test/make_unique_throws_test.cpp b/test/make_unique_throws_test.cpp index c8fdcc8..2032a2e 100644 --- a/test/make_unique_throws_test.cpp +++ b/test/make_unique_throws_test.cpp @@ -1,10 +1,9 @@ /* -(c) 2014 Glen Joseph Fernandes - +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) @@ -13,17 +12,17 @@ http://boost.org/LICENSE_1_0.txt class type { public: - static unsigned int instances; + static unsigned instances; - explicit type() { + type() { if (instances == 0) { throw true; } - instances++; + ++instances; } ~type() { - instances--; + --instances; } private: @@ -31,7 +30,7 @@ private: type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { @@ -42,14 +41,11 @@ int main() } catch (...) { BOOST_TEST(type::instances == 0); } - return boost::report_errors(); } #else - int main() { return 0; } - #endif diff --git a/test/make_unique_value_test.cpp b/test/make_unique_value_test.cpp index 4b34af8..c7af67f 100644 --- a/test/make_unique_value_test.cpp +++ b/test/make_unique_value_test.cpp @@ -1,10 +1,9 @@ /* -(c) 2014 Glen Joseph Fernandes - +Copyright 2014 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #if !defined(BOOST_NO_CXX11_SMART_PTR) @@ -19,42 +18,39 @@ struct type { int main() { { - std::unique_ptr a1 = boost::make_unique(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1->x == 0); - BOOST_TEST(a1->y == 0); + std::unique_ptr result = boost::make_unique(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 0); + BOOST_TEST(result->y == 0); } - { - std::unique_ptr a1 = boost::make_unique(); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1->x == 0); - BOOST_TEST(a1->y == 0); + std::unique_ptr result = + boost::make_unique(); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 0); + BOOST_TEST(result->y == 0); } - #if !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { - std::unique_ptr a1 = boost::make_unique({ 1, 2 }); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1->x == 1); - BOOST_TEST(a1->y == 2); + std::unique_ptr result = + boost::make_unique({ 1, 2 }); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 1); + BOOST_TEST(result->y == 2); } - { - std::unique_ptr a1 = boost::make_unique({ 1, 2 }); - BOOST_TEST(a1.get() != 0); - BOOST_TEST(a1->x == 1); - BOOST_TEST(a1->y == 2); + std::unique_ptr result = + boost::make_unique({ 1, 2 }); + BOOST_TEST(result.get() != 0); + BOOST_TEST(result->x == 1); + BOOST_TEST(result->y == 2); } #endif - return boost::report_errors(); } #else - int main() { return 0; } - #endif