• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <boost/config.hpp>
2 
3 //  sp_convertible_test2.cpp
4 //
5 //  Copyright 2012, 2017 Peter Dimov
6 //
7 //  Distributed under the Boost Software License, Version 1.0.
8 //  See accompanying file LICENSE_1_0.txt or copy at
9 //  http://www.boost.org/LICENSE_1_0.txt
10 
11 #include <boost/shared_ptr.hpp>
12 #include <boost/weak_ptr.hpp>
13 #include <boost/core/lightweight_test.hpp>
14 #include <boost/type_traits/is_convertible.hpp>
15 
16 //
17 
18 class X;
19 
20 class B
21 {
22 };
23 
24 class D: public B
25 {
26 };
27 
28 using boost::is_convertible;
29 
30 #define TEST_CV_TRUE_( S1, T, S2, U ) \
31     BOOST_TEST(( is_convertible< S1<T>, S2<U> >::value == true )); \
32     BOOST_TEST(( is_convertible< S1<T>, S2<const U> >::value == true )); \
33     BOOST_TEST(( is_convertible< S1<T>, S2<volatile U> >::value == true )); \
34     BOOST_TEST(( is_convertible< S1<T>, S2<const volatile U> >::value == true )); \
35     BOOST_TEST(( is_convertible< S1<const T>, S2<U> >::value == false )); \
36     BOOST_TEST(( is_convertible< S1<const T>, S2<const U> >::value == true )); \
37     BOOST_TEST(( is_convertible< S1<const T>, S2<volatile U> >::value == false )); \
38     BOOST_TEST(( is_convertible< S1<const T>, S2<const volatile U> >::value == true )); \
39     BOOST_TEST(( is_convertible< S1<volatile T>, S2<U> >::value == false )); \
40     BOOST_TEST(( is_convertible< S1<volatile T>, S2<const U> >::value == false )); \
41     BOOST_TEST(( is_convertible< S1<volatile T>, S2<volatile U> >::value == true )); \
42     BOOST_TEST(( is_convertible< S1<volatile T>, S2<const volatile U> >::value == true )); \
43     BOOST_TEST(( is_convertible< S1<const volatile T>, S2<U> >::value == false )); \
44     BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const U> >::value == false )); \
45     BOOST_TEST(( is_convertible< S1<const volatile T>, S2<volatile U> >::value == false )); \
46     BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const volatile U> >::value == true ));
47 
48 #define TEST_CV_FALSE_( S1, T, S2, U ) \
49     BOOST_TEST(( is_convertible< S1<T>, S2<U> >::value == false )); \
50     BOOST_TEST(( is_convertible< S1<T>, S2<const U> >::value == false )); \
51     BOOST_TEST(( is_convertible< S1<T>, S2<volatile U> >::value == false )); \
52     BOOST_TEST(( is_convertible< S1<T>, S2<const volatile U> >::value == false )); \
53     BOOST_TEST(( is_convertible< S1<const T>, S2<U> >::value == false )); \
54     BOOST_TEST(( is_convertible< S1<const T>, S2<const U> >::value == false )); \
55     BOOST_TEST(( is_convertible< S1<const T>, S2<volatile U> >::value == false )); \
56     BOOST_TEST(( is_convertible< S1<const T>, S2<const volatile U> >::value == false )); \
57     BOOST_TEST(( is_convertible< S1<volatile T>, S2<U> >::value == false )); \
58     BOOST_TEST(( is_convertible< S1<volatile T>, S2<const U> >::value == false )); \
59     BOOST_TEST(( is_convertible< S1<volatile T>, S2<volatile U> >::value == false )); \
60     BOOST_TEST(( is_convertible< S1<volatile T>, S2<const volatile U> >::value == false )); \
61     BOOST_TEST(( is_convertible< S1<const volatile T>, S2<U> >::value == false )); \
62     BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const U> >::value == false )); \
63     BOOST_TEST(( is_convertible< S1<const volatile T>, S2<volatile U> >::value == false )); \
64     BOOST_TEST(( is_convertible< S1<const volatile T>, S2<const volatile U> >::value == false ));
65 
66 using boost::shared_ptr;
67 using boost::weak_ptr;
68 
69 #define TEST_CV_TRUE( T, U ) \
70     TEST_CV_TRUE_( shared_ptr, T, shared_ptr, U ) \
71     TEST_CV_TRUE_( shared_ptr, T, weak_ptr, U ) \
72     TEST_CV_TRUE_( weak_ptr, T, weak_ptr, U )
73 
74 #define TEST_CV_FALSE( T, U ) \
75     TEST_CV_FALSE_( shared_ptr, T, shared_ptr, U ) \
76     TEST_CV_FALSE_( shared_ptr, T, weak_ptr, U ) \
77     TEST_CV_FALSE_( weak_ptr, T, weak_ptr, U )
78 
main()79 int main()
80 {
81 #if !defined( BOOST_SP_NO_SP_CONVERTIBLE )
82 
83     TEST_CV_TRUE( X, X )
84     TEST_CV_TRUE( X, void )
85     TEST_CV_FALSE( void, X )
86     TEST_CV_TRUE( D, B )
87     TEST_CV_FALSE( B, D )
88 
89     TEST_CV_TRUE( X[], X[] )
90     TEST_CV_FALSE( D[], B[] )
91 
92     TEST_CV_TRUE( X[3], X[3] )
93     TEST_CV_FALSE( X[3], X[4] )
94     TEST_CV_FALSE( D[3], B[3] )
95 
96     TEST_CV_TRUE( X[3], X[] )
97     TEST_CV_FALSE( X[], X[3] )
98 
99     TEST_CV_TRUE( X[], void )
100     TEST_CV_FALSE( void, X[] )
101 
102     TEST_CV_TRUE( X[3], void )
103     TEST_CV_FALSE( void, X[3] )
104 
105 #endif
106 
107     return boost::report_errors();
108 }
109