source: NonGTP/Boost/boost/type_traits/is_const.hpp @ 857

Revision 857, 4.4 KB checked in by igarcia, 18 years ago (diff)
Line 
1
2//  (C) Copyright Dave Abrahams, Steve Cleary, Beman Dawes,
3//      Howard Hinnant and John Maddock 2000.
4//  (C) Copyright Mat Marcus, Jesse Jones and Adobe Systems Inc 2001
5
6//  Use, modification and distribution are subject to the Boost Software License,
7//  Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8//  http://www.boost.org/LICENSE_1_0.txt).
9//
10//  See http://www.boost.org/libs/type_traits for most recent version including documentation.
11
12//    Fixed is_pointer, is_reference, is_const, is_volatile, is_same,
13//    is_member_pointer based on the Simulated Partial Specialization work
14//    of Mat Marcus and Jesse Jones. See  http://opensource.adobe.com or
15//    http://groups.yahoo.com/group/boost/message/5441
16//    Some workarounds in here use ideas suggested from "Generic<Programming>:
17//    Mappings between Types and Values"
18//    by Andrei Alexandrescu (see http://www.cuj.com/experts/1810/alexandr.html).
19
20
21#ifndef BOOST_TT_IS_CONST_HPP_INCLUDED
22#define BOOST_TT_IS_CONST_HPP_INCLUDED
23
24#include "boost/config.hpp"
25
26#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
27#   include "boost/type_traits/detail/cv_traits_impl.hpp"
28#   ifdef __GNUC__
29#       include <boost/type_traits/is_reference.hpp>
30#   endif
31#else
32#   include "boost/type_traits/is_reference.hpp"
33#   include "boost/type_traits/is_array.hpp"
34#   include "boost/type_traits/detail/yes_no_type.hpp"
35#   include "boost/type_traits/detail/false_result.hpp"
36#endif
37
38// should be the last #include
39#include "boost/type_traits/detail/bool_trait_def.hpp"
40
41namespace boost {
42
43#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
44
45//* is a type T  declared const - is_const<T>
46BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_const,T,::boost::detail::cv_traits_imp<T*>::is_const)
47BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T&,false)
48
49#if defined(__BORLANDC__) && (__BORLANDC__ < 0x600)
50// these are illegal specialisations; cv-qualifies applied to
51// references have no effect according to [8.3.2p1],
52// C++ Builder requires them though as it treats cv-qualified
53// references as distinct types...
54BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T& const,false)
55BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T& volatile,false)
56BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T& const volatile,false)
57#endif
58
59#if defined(__GNUC__) && (__GNUC__ < 3)
60// special case for gcc where illegally cv-qualified reference types can be
61// generated in some corner cases:
62BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T const,!(::boost::is_reference<T>::value))
63BOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T volatile const,!(::boost::is_reference<T>::value))
64#endif
65
66#else
67
68namespace detail {
69
70using ::boost::type_traits::yes_type;
71using ::boost::type_traits::no_type;
72
73yes_type is_const_tester(const volatile void*);
74no_type is_const_tester(volatile void *);
75
76template <bool is_ref, bool array>
77struct is_const_helper
78    : ::boost::type_traits::false_result
79{
80};
81
82template <>
83struct is_const_helper<false,false>
84{
85    template <typename T> struct result_
86    {
87        static T* t;
88        BOOST_STATIC_CONSTANT(bool, value = (
89            sizeof(detail::yes_type) == sizeof(detail::is_const_tester(t))
90            ));
91    };
92};
93
94template <>
95struct is_const_helper<false,true>
96{
97    template <typename T> struct result_
98    {
99        static T t;
100        BOOST_STATIC_CONSTANT(bool, value = (
101            sizeof(detail::yes_type) == sizeof(detail::is_const_tester(&t))
102            ));
103    };
104};
105
106template <typename T>
107struct is_const_impl
108    : is_const_helper<
109          is_reference<T>::value
110        , is_array<T>::value
111        >::template result_<T>
112{
113};
114
115BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void,false)
116#ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS
117BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void const,true)
118BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void volatile,false)
119BOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void const volatile,true)
120#endif
121
122} // namespace detail
123
124//* is a type T  declared const - is_const<T>
125BOOST_TT_AUX_BOOL_TRAIT_DEF1(is_const,T,::boost::detail::is_const_impl<T>::value)
126
127#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
128
129} // namespace boost
130
131#include "boost/type_traits/detail/bool_trait_undef.hpp"
132
133#endif // BOOST_TT_IS_CONST_HPP_INCLUDED
134
Note: See TracBrowser for help on using the repository browser.