• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Boost.Pointer Container
3 //
4 //  Copyright Thorsten Ottosen 2003-2005. Use, modification and
5 //  distribution is subject to the Boost Software License, Version
6 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 //  http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // For more information, see http://www.boost.org/libs/ptr_container/
10 //
11 
12 
13 #ifndef BOOST_INDIRECT_CONTAINER_NULLABLE_HPP
14 #define BOOST_INDIRECT_CONTAINER_NULLABLE_HPP
15 
16 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
17 # pragma once
18 #endif
19 
20 #include <boost/type_traits/detail/yes_no_type.hpp>
21 #include <boost/type_traits/is_const.hpp>
22 #include <boost/mpl/eval_if.hpp>
23 #include <boost/mpl/identity.hpp>
24 #include <boost/config.hpp>
25 
26 namespace boost
27 {
28 
29     template< class T >
30     struct nullable
31     {
32         typedef T type;
33     };
34 
35     namespace ptr_container_detail
36     {
37         template< class T >
38         type_traits::yes_type is_nullable( const nullable<T>* );
39 
40         type_traits::no_type is_nullable( ... );
41     }
42 
43     template< class T >
44     struct is_nullable
45     {
46     private:
47             BOOST_STATIC_CONSTANT( T*, var );
48     public:
49 
50 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
51 #pragma warning(push)
52 #pragma warning(disable:6334)
53 #endif
54 
55             BOOST_STATIC_CONSTANT(bool, value = sizeof( ptr_container_detail::is_nullable( var ) )
56                                                 == sizeof( type_traits::yes_type ) );
57 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
58 #pragma warning(pop)
59 #endif
60 
61     };
62 
63     template< class T >
64     struct remove_nullable
65     {
66         typedef BOOST_DEDUCED_TYPENAME mpl::eval_if< is_nullable<T>,
67                                                       T,
68                                             mpl::identity<T> >::type
69             type;
70     };
71 
72     namespace ptr_container_detail
73     {
74         template< class T >
75         struct void_ptr
76         {
77             typedef BOOST_DEDUCED_TYPENAME
78                 mpl::if_c< boost::is_const<
79                               BOOST_DEDUCED_TYPENAME boost::remove_nullable<T>::type >::value,
80                            const void*, void* >::type type;
81         };
82     }
83 }
84 
85 #endif
86