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_object.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>(); 36 BOOST_TEST(a1.get() != 0); 37 } 38 39 BOOST_TEST(type::instances == 0); 40 { 41 std::unique_ptr<type> a1 = boost::make_unique_noinit<type>(); 42 BOOST_TEST(a1.get() != 0); 43 BOOST_TEST(type::instances == 1); 44 a1.reset(); 45 BOOST_TEST(type::instances == 0); 46 } 47 48 BOOST_TEST(type::instances == 0); 49 { 50 std::unique_ptr<const type> a1 = boost::make_unique_noinit<const type>(); 51 BOOST_TEST(a1.get() != 0); 52 BOOST_TEST(type::instances == 1); 53 a1.reset(); 54 BOOST_TEST(type::instances == 0); 55 } 56 57 return boost::report_errors(); 58 } 59 #else 60 main()61int main() { 62 return 0; 63 } 64 65 #endif 66