1 //
2 //  pointer_to_other_test.cpp - a test for boost/pointer_to_other.hpp
3 //
4 //  Copyright (c) 2005 Peter Dimov
5 //
6 // Distributed under the Boost Software License, Version 1.0. (See
7 // accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #include <boost/pointer_to_other.hpp>
12 
13 #include <boost/shared_ptr.hpp>
14 #include <boost/shared_array.hpp>
15 #include <boost/scoped_ptr.hpp>
16 #include <boost/scoped_array.hpp>
17 #include <boost/intrusive_ptr.hpp>
18 
19 #include <boost/config.hpp>
20 
21 #include <memory>
22 
23 
assert_same_type(T ** pt=0,U ** pu=0)24 template<class T, class U> void assert_same_type( T** pt = 0, U** pu = 0 )
25 {
26     pt = pu;
27 }
28 
29 struct X;
30 struct Y;
31 
main()32 int main()
33 {
34     // shared_ptr
35 
36     assert_same_type< boost::pointer_to_other< boost::shared_ptr<X>, Y >::type, boost::shared_ptr<Y> >();
37     assert_same_type< boost::pointer_to_other< boost::shared_ptr<X>, void >::type, boost::shared_ptr<void> >();
38     assert_same_type< boost::pointer_to_other< boost::shared_ptr<void>, Y >::type, boost::shared_ptr<Y> >();
39 
40     // shared_array
41 
42     assert_same_type< boost::pointer_to_other< boost::shared_array<X>, Y >::type, boost::shared_array<Y> >();
43     assert_same_type< boost::pointer_to_other< boost::shared_array<X>, void >::type, boost::shared_array<void> >();
44     assert_same_type< boost::pointer_to_other< boost::shared_array<void>, Y >::type, boost::shared_array<Y> >();
45 
46     // scoped_ptr
47 
48     assert_same_type< boost::pointer_to_other< boost::scoped_ptr<X>, Y >::type, boost::scoped_ptr<Y> >();
49     assert_same_type< boost::pointer_to_other< boost::scoped_ptr<X>, void >::type, boost::scoped_ptr<void> >();
50     assert_same_type< boost::pointer_to_other< boost::scoped_ptr<void>, Y >::type, boost::scoped_ptr<Y> >();
51 
52     // scoped_array
53 
54     assert_same_type< boost::pointer_to_other< boost::scoped_array<X>, Y >::type, boost::scoped_array<Y> >();
55     assert_same_type< boost::pointer_to_other< boost::scoped_array<X>, void >::type, boost::scoped_array<void> >();
56     assert_same_type< boost::pointer_to_other< boost::scoped_array<void>, Y >::type, boost::scoped_array<Y> >();
57 
58     // intrusive_ptr
59 
60     assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, Y >::type, boost::intrusive_ptr<Y> >();
61     assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<X>, void >::type, boost::intrusive_ptr<void> >();
62     assert_same_type< boost::pointer_to_other< boost::intrusive_ptr<void>, Y >::type, boost::intrusive_ptr<Y> >();
63 
64 #if !defined( BOOST_NO_AUTO_PTR )
65 
66     // auto_ptr
67 
68     assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, Y >::type, std::auto_ptr<Y> >();
69     assert_same_type< boost::pointer_to_other< std::auto_ptr<X>, void >::type, std::auto_ptr<void> >();
70     assert_same_type< boost::pointer_to_other< std::auto_ptr<void>, Y >::type, std::auto_ptr<Y> >();
71 
72 #endif
73 
74     // raw pointer
75 
76     assert_same_type< boost::pointer_to_other< X *, Y >::type, Y * >();
77     assert_same_type< boost::pointer_to_other< X *, void >::type, void * >();
78     assert_same_type< boost::pointer_to_other< void *, Y >::type, Y * >();
79 
80     return 0;
81 }
82