blob: 919b750421d2a26cc5bec6eb26d6d2040cfeba24 [file] [log] [blame]
Jeff Thompsonf7d49942013-08-01 16:47:40 -07001
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070021#ifndef NDNBOOST_TT_IS_CONST_HPP_INCLUDED
22#define NDNBOOST_TT_IS_CONST_HPP_INCLUDED
Jeff Thompsonf7d49942013-08-01 16:47:40 -070023
Jeff Thompson2277ce52013-08-01 17:34:11 -070024#include <ndnboost/config.hpp>
25#include <ndnboost/detail/workaround.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070026
Jeff Thompson3d613fd2013-10-15 15:39:04 -070027#ifndef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompson2277ce52013-08-01 17:34:11 -070028# include <ndnboost/type_traits/detail/cv_traits_impl.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070029# ifdef __GNUC__
Jeff Thompson2277ce52013-08-01 17:34:11 -070030# include <ndnboost/type_traits/is_reference.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070031# endif
Jeff Thompson3d613fd2013-10-15 15:39:04 -070032# if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1400)
Jeff Thompson2277ce52013-08-01 17:34:11 -070033# include <ndnboost/type_traits/remove_bounds.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070034# endif
35#else
Jeff Thompson2277ce52013-08-01 17:34:11 -070036# include <ndnboost/type_traits/is_reference.hpp>
37# include <ndnboost/type_traits/is_array.hpp>
38# include <ndnboost/type_traits/detail/yes_no_type.hpp>
39# include <ndnboost/type_traits/detail/false_result.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070040#endif
41
42// should be the last #include
Jeff Thompson2277ce52013-08-01 17:34:11 -070043#include <ndnboost/type_traits/detail/bool_trait_def.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070044
45namespace ndnboost {
46
47#if defined( __CODEGEARC__ )
48
Jeff Thompson3d613fd2013-10-15 15:39:04 -070049NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_const,T,__is_const(T))
Jeff Thompsonf7d49942013-08-01 16:47:40 -070050
Jeff Thompson3d613fd2013-10-15 15:39:04 -070051#elif !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsonf7d49942013-08-01 16:47:40 -070052
53namespace detail{
54//
55// We can't filter out rvalue_references at the same level as
56// references or we get ambiguities from msvc:
57//
58template <class T>
59struct is_const_rvalue_filter
60{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070061#if NDNBOOST_WORKAROUND(NDNBOOST_MSVC, < 1400)
62 NDNBOOST_STATIC_CONSTANT(bool, value = ::ndnboost::detail::cv_traits_imp<typename ndnboost::remove_bounds<T>::type*>::is_const);
Jeff Thompsonf7d49942013-08-01 16:47:40 -070063#else
Jeff Thompson3d613fd2013-10-15 15:39:04 -070064 NDNBOOST_STATIC_CONSTANT(bool, value = ::ndnboost::detail::cv_traits_imp<T*>::is_const);
Jeff Thompsonf7d49942013-08-01 16:47:40 -070065#endif
66};
Jeff Thompson3d613fd2013-10-15 15:39:04 -070067#ifndef NDNBOOST_NO_CXX11_RVALUE_REFERENCES
Jeff Thompsonf7d49942013-08-01 16:47:40 -070068template <class T>
69struct is_const_rvalue_filter<T&&>
70{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070071 NDNBOOST_STATIC_CONSTANT(bool, value = false);
Jeff Thompsonf7d49942013-08-01 16:47:40 -070072};
73#endif
74}
75
76//* is a type T declared const - is_const<T>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070077NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_const,T,::ndnboost::detail::is_const_rvalue_filter<T>::value)
78NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T&,false)
Jeff Thompsonf7d49942013-08-01 16:47:40 -070079
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080#if defined(NDNBOOST_ILLEGAL_CV_REFERENCES)
Jeff Thompsonf7d49942013-08-01 16:47:40 -070081// these are illegal specialisations; cv-qualifies applied to
82// references have no effect according to [8.3.2p1],
83// C++ Builder requires them though as it treats cv-qualified
84// references as distinct types...
Jeff Thompson3d613fd2013-10-15 15:39:04 -070085NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T& const,false)
86NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T& volatile,false)
87NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T& const volatile,false)
Jeff Thompsonf7d49942013-08-01 16:47:40 -070088#endif
89
90#if defined(__GNUC__) && (__GNUC__ < 3)
91// special case for gcc where illegally cv-qualified reference types can be
92// generated in some corner cases:
Jeff Thompson3d613fd2013-10-15 15:39:04 -070093NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T const,!(::ndnboost::is_reference<T>::value))
94NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_const,T volatile const,!(::ndnboost::is_reference<T>::value))
Jeff Thompsonf7d49942013-08-01 16:47:40 -070095#endif
96
97#else
98
99namespace detail {
100
101using ::ndnboost::type_traits::yes_type;
102using ::ndnboost::type_traits::no_type;
103
104yes_type is_const_tester(const volatile void*);
105no_type is_const_tester(volatile void *);
106
107template <bool is_ref, bool array>
108struct is_const_helper
109 : public ::ndnboost::type_traits::false_result
110{
111};
112
113template <>
114struct is_const_helper<false,false>
115{
116 template <typename T> struct result_
117 {
118 static T* t;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700119 NDNBOOST_STATIC_CONSTANT(bool, value = (
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700120 sizeof(ndnboost::detail::yes_type) == sizeof(ndnboost::detail::is_const_tester(t))
121 ));
122 };
123};
124
125template <>
126struct is_const_helper<false,true>
127{
128 template <typename T> struct result_
129 {
130 static T t;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700131 NDNBOOST_STATIC_CONSTANT(bool, value = (
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700132 sizeof(ndnboost::detail::yes_type) == sizeof(ndnboost::detail::is_const_tester(&t))
133 ));
134 };
135};
136
137template <typename T>
138struct is_const_impl
139 : public is_const_helper<
140 is_reference<T>::value
141 , is_array<T>::value
142 >::template result_<T>
143{
144};
145
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700146NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void,false)
147#ifndef NDNBOOST_NO_CV_VOID_SPECIALIZATIONS
148NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void const,true)
149NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void volatile,false)
150NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_const,void const volatile,true)
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700151#endif
152
153} // namespace detail
154
155//* is a type T declared const - is_const<T>
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700156NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_const,T,::ndnboost::detail::is_const_impl<T>::value)
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700157
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700158#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700159
160} // namespace ndnboost
161
Jeff Thompson2277ce52013-08-01 17:34:11 -0700162#include <ndnboost/type_traits/detail/bool_trait_undef.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700163
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700164#endif // NDNBOOST_TT_IS_CONST_HPP_INCLUDED
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700165