| 1 | // |
|---|---|
| 2 | // get_pointer_test.cpp |
| 3 | // |
| 4 | // Copyright 2014, 2017 Peter Dimov |
| 5 | // |
| 6 | // Distributed under the Boost Software License, Version 1.0. |
| 7 | // See accompanying file LICENSE_1_0.txt or copy at |
| 8 | // http://www.boost.org/LICENSE_1_0.txt |
| 9 | // |
| 10 | |
| 11 | #if defined(__GNUC__) |
| 12 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" // std::auto_ptr |
| 13 | #endif |
| 14 | |
| 15 | #include <boost/get_pointer.hpp> |
| 16 | #include <boost/core/lightweight_test.hpp> |
| 17 | #include <memory> |
| 18 | |
| 19 | struct X |
| 20 | { |
| 21 | }; |
| 22 | |
| 23 | int main() |
| 24 | { |
| 25 | using boost::get_pointer; |
| 26 | |
| 27 | { |
| 28 | X * p = new X; |
| 29 | BOOST_TEST( get_pointer( p ) == p ); |
| 30 | |
| 31 | delete p; |
| 32 | } |
| 33 | |
| 34 | { |
| 35 | X * p = 0; |
| 36 | BOOST_TEST( get_pointer( p ) == 0 ); |
| 37 | } |
| 38 | |
| 39 | #if !defined( BOOST_NO_AUTO_PTR ) |
| 40 | |
| 41 | { |
| 42 | std::auto_ptr< X > p( new X ); |
| 43 | BOOST_TEST( get_pointer( p ) == p.get() ); |
| 44 | } |
| 45 | |
| 46 | { |
| 47 | std::auto_ptr< X > p; |
| 48 | BOOST_TEST( get_pointer( p ) == 0 ); |
| 49 | } |
| 50 | |
| 51 | #endif |
| 52 | |
| 53 | #if !defined( BOOST_NO_CXX11_SMART_PTR ) |
| 54 | |
| 55 | { |
| 56 | std::unique_ptr< X > p( new X ); |
| 57 | BOOST_TEST( get_pointer( p ) == p.get() ); |
| 58 | } |
| 59 | |
| 60 | { |
| 61 | std::unique_ptr< X > p; |
| 62 | BOOST_TEST( get_pointer( p ) == 0 ); |
| 63 | } |
| 64 | |
| 65 | { |
| 66 | std::shared_ptr< X > p( new X ); |
| 67 | BOOST_TEST( get_pointer( p ) == p.get() ); |
| 68 | } |
| 69 | |
| 70 | { |
| 71 | std::shared_ptr< X > p; |
| 72 | BOOST_TEST( get_pointer( p ) == 0 ); |
| 73 | } |
| 74 | |
| 75 | #endif |
| 76 | |
| 77 | return boost::report_errors(); |
| 78 | } |
| 79 |
