]> git.lyx.org Git - lyx.git/blob - boost/boost/type_traits/is_const.hpp
update to boost 1.30.1
[lyx.git] / boost / boost / type_traits / is_const.hpp
1
2 // (C) Copyright Dave Abrahams, Steve Cleary, Beman Dawes, Howard
3 // Hinnant & John Maddock 2000.  Permission to copy, use, modify,
4 // sell and distribute this software is granted provided this
5 // copyright notice appears in all copies. This software is provided
6 // "as is" without express or implied warranty, and with no claim as
7 // to its suitability for any purpose.
8 //
9 // See http://www.boost.org for most recent version including documentation.
10
11 #ifndef BOOST_TT_IS_CONST_HPP_INCLUDED
12 #define BOOST_TT_IS_CONST_HPP_INCLUDED
13
14 #include "boost/config.hpp"
15
16 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
17 #   include "boost/type_traits/detail/cv_traits_impl.hpp"
18 #   ifdef __GNUC__
19 #       include <boost/type_traits/is_reference.hpp>
20 #   endif
21 #else
22 #   include "boost/type_traits/is_reference.hpp"
23 #   include "boost/type_traits/is_array.hpp"
24 #   include "boost/type_traits/detail/yes_no_type.hpp"
25 #   include "boost/type_traits/detail/false_result.hpp"
26 #endif
27
28 // should be the last #include
29 #include "boost/type_traits/detail/bool_trait_def.hpp"
30
31 namespace boost {
32
33 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
34
35 //* is a type T  declared const - is_const<T>
36 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_const,T,::boost::detail::cv_traits_imp<T*>::is_const)
37 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T&,false)
38
39 #if defined(__BORLANDC__)
40 // these are illegal specialisations; cv-qualifies applied to
41 // references have no effect according to [8.3.2p1],
42 // C++ Builder requires them though as it treats cv-qualified
43 // references as distinct types...
44 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T& const,false)
45 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T& volatile,false)
46 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T& const volatile,false)
47 #endif
48
49 #if defined(__GNUC__) && (__GNUC__ < 3)
50 // special case for gcc where illegally cv-qualified reference types can be
51 // generated in some corner cases:
52 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T const,!(::boost::is_reference<T>::value))
53 BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T volatile const,!(::boost::is_reference<T>::value))
54 #endif
55
56 #else
57
58 namespace detail {
59
60 using ::boost::type_traits::yes_type;
61 using ::boost::type_traits::no_type;
62
63 yes_type is_const_tester(const volatile void*);
64 no_type is_const_tester(volatile void *);
65
66 template <bool is_ref, bool array>
67 struct is_const_helper
68     : ::boost::type_traits::false_result
69 {
70 };
71
72 template <>
73 struct is_const_helper<false,false>
74 {
75     template <typename T> struct result_
76     {
77         static T* t;
78         BOOST_STATIC_CONSTANT(bool, value = (
79             sizeof(detail::yes_type) == sizeof(detail::is_const_tester(t))
80             ));
81     };      
82 };
83
84 template <>
85 struct is_const_helper<false,true>
86 {
87     template <typename T> struct result_
88     {
89         static T t;
90         BOOST_STATIC_CONSTANT(bool, value = (
91             sizeof(detail::yes_type) == sizeof(detail::is_const_tester(&t))
92             ));
93     };      
94 };
95
96 template <typename T>
97 struct is_const_impl
98     : is_const_helper<
99           is_reference<T>::value
100         , is_array<T>::value
101         >::template result_<T>
102
103 };
104
105 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void,false)
106 #ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
107 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void const,true)
108 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void volatile,false)
109 BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void const volatile,true)
110 #endif
111
112 } // namespace detail
113
114 //* is a type T  declared const - is_const<T>
115 BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_const,T,::boost::detail::is_const_impl<T>::value)
116
117 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
118
119 } // namespace boost
120
121 #include "boost/type_traits/detail/bool_trait_undef.hpp"
122
123 #endif // BOOST_TT_IS_CONST_HPP_INCLUDED
124