1 /* 2 * Copyright (c) 2012-2014 Glen Joseph Fernandes 3 * glenfe at live dot com 4 * 5 * Distributed under the Boost Software License, 6 * Version 1.0. (See accompanying file LICENSE_1_0.txt 7 * or copy at http://boost.org/LICENSE_1_0.txt) 8 */ 9 #include <boost/config.hpp> 10 #if !defined(BOOST_NO_CXX11_SMART_PTR) 11 #include <boost/detail/lightweight_test.hpp> 12 #include <boost/smart_ptr/make_unique_array.hpp> 13 14 class type { 15 public: 16 static unsigned int instances; 17 type()18 explicit type() { 19 instances++; 20 } 21 ~type()22 ~type() { 23 instances--; 24 } 25 26 private: 27 type(const type&); 28 type& operator=(const type&); 29 }; 30 31 unsigned int type::instances = 0; 32 main()33int main() { 34 { 35 std::unique_ptr<int[]> a1 = boost::make_unique_noinit<int[]>(3); 36 BOOST_TEST(a1.get() != 0); 37 } 38 39 { 40 std::unique_ptr<int[][2]> a1 = boost::make_unique_noinit<int[][2]>(2); 41 BOOST_TEST(a1.get() != 0); 42 } 43 44 BOOST_TEST(type::instances == 0); 45 { 46 std::unique_ptr<type[]> a1 = boost::make_unique_noinit<type[]>(3); 47 BOOST_TEST(a1.get() != 0); 48 BOOST_TEST(type::instances == 3); 49 a1.reset(); 50 BOOST_TEST(type::instances == 0); 51 } 52 53 BOOST_TEST(type::instances == 0); 54 { 55 std::unique_ptr<type[][2]> a1 = boost::make_unique_noinit<type[][2]>(2); 56 BOOST_TEST(a1.get() != 0); 57 BOOST_TEST(type::instances == 4); 58 a1.reset(); 59 BOOST_TEST(type::instances == 0); 60 } 61 62 BOOST_TEST(type::instances == 0); 63 { 64 std::unique_ptr<const type[]> a1 = boost::make_unique_noinit<const type[]>(3); 65 BOOST_TEST(a1.get() != 0); 66 BOOST_TEST(type::instances == 3); 67 a1.reset(); 68 BOOST_TEST(type::instances == 0); 69 } 70 71 BOOST_TEST(type::instances == 0); 72 { 73 std::unique_ptr<const type[][2]> a1 = boost::make_unique_noinit<const type[][2]>(2); 74 BOOST_TEST(a1.get() != 0); 75 BOOST_TEST(type::instances == 4); 76 a1.reset(); 77 BOOST_TEST(type::instances == 0); 78 } 79 80 return boost::report_errors(); 81 } 82 #else 83 main()84int main() { 85 return 0; 86 } 87 88 #endif 89