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