blob: 812d36de74d71585a7bbd80f43d08a7338358fb6 [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_POINTER_HPP_INCLUDED
22#define NDNBOOST_TT_IS_POINTER_HPP_INCLUDED
Jeff Thompsonf7d49942013-08-01 16:47:40 -070023
Jeff Thompson2277ce52013-08-01 17:34:11 -070024#include <ndnboost/type_traits/is_member_pointer.hpp>
25#include <ndnboost/type_traits/detail/ice_and.hpp>
26#include <ndnboost/type_traits/detail/ice_not.hpp>
27#include <ndnboost/type_traits/config.hpp>
Jeff Thompson3d613fd2013-10-15 15:39:04 -070028#if !NDNBOOST_WORKAROUND(NDNBOOST_MSVC,<=1300)
Jeff Thompson2277ce52013-08-01 17:34:11 -070029#include <ndnboost/type_traits/remove_cv.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070030#endif
31
Jeff Thompson3d613fd2013-10-15 15:39:04 -070032#ifdef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompson2277ce52013-08-01 17:34:11 -070033# include <ndnboost/type_traits/is_reference.hpp>
34# include <ndnboost/type_traits/is_array.hpp>
35# include <ndnboost/type_traits/detail/is_function_ptr_tester.hpp>
36# include <ndnboost/type_traits/detail/false_result.hpp>
37# include <ndnboost/type_traits/detail/ice_or.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070038#endif
39
40// should be the last #include
Jeff Thompson2277ce52013-08-01 17:34:11 -070041#include <ndnboost/type_traits/detail/bool_trait_def.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070042
43namespace ndnboost {
44
45#if defined( __CODEGEARC__ )
Jeff Thompson3d613fd2013-10-15 15:39:04 -070046NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_pointer,T,__is_pointer(T))
47#elif !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsonf7d49942013-08-01 16:47:40 -070048
49namespace detail {
50
51template< typename T > struct is_pointer_helper
52{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070053 NDNBOOST_STATIC_CONSTANT(bool, value = false);
Jeff Thompsonf7d49942013-08-01 16:47:40 -070054};
55
56# define TT_AUX_BOOL_TRAIT_HELPER_PARTIAL_SPEC(helper,sp,result) \
57template< typename T > struct helper<sp> \
58{ \
Jeff Thompson3d613fd2013-10-15 15:39:04 -070059 NDNBOOST_STATIC_CONSTANT(bool, value = result); \
Jeff Thompsonf7d49942013-08-01 16:47:40 -070060}; \
61/**/
62
63TT_AUX_BOOL_TRAIT_HELPER_PARTIAL_SPEC(is_pointer_helper,T*,true)
64
65# undef TT_AUX_BOOL_TRAIT_HELPER_PARTIAL_SPEC
66
67template< typename T >
68struct is_pointer_impl
69{
Jeff Thompson3d613fd2013-10-15 15:39:04 -070070#if NDNBOOST_WORKAROUND(NDNBOOST_MSVC,<=1300)
71 NDNBOOST_STATIC_CONSTANT(bool, value =
Jeff Thompsonf7d49942013-08-01 16:47:40 -070072 (::ndnboost::type_traits::ice_and<
73 ::ndnboost::detail::is_pointer_helper<T>::value
74 , ::ndnboost::type_traits::ice_not<
75 ::ndnboost::is_member_pointer<T>::value
76 >::value
77 >::value)
78 );
79#else
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080 NDNBOOST_STATIC_CONSTANT(bool, value =
Jeff Thompsonf7d49942013-08-01 16:47:40 -070081 (::ndnboost::type_traits::ice_and<
82 ::ndnboost::detail::is_pointer_helper<typename remove_cv<T>::type>::value
83 , ::ndnboost::type_traits::ice_not<
84 ::ndnboost::is_member_pointer<T>::value
85 >::value
86 >::value)
87 );
88#endif
89};
90
91} // namespace detail
92
Jeff Thompson3d613fd2013-10-15 15:39:04 -070093NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_pointer,T,::ndnboost::detail::is_pointer_impl<T>::value)
Jeff Thompsonf7d49942013-08-01 16:47:40 -070094
95#if defined(__BORLANDC__) && !defined(__COMO__) && (__BORLANDC__ < 0x600)
Jeff Thompson3d613fd2013-10-15 15:39:04 -070096NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_pointer,T&,false)
97NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_pointer,T& const,false)
98NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_pointer,T& volatile,false)
99NDNBOOST_TT_AUX_BOOL_TRAIT_PARTIAL_SPEC1_1(typename T,is_pointer,T& const volatile,false)
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700100#endif
101
102#else // no partial template specialization
103
104namespace detail {
105
106struct pointer_helper
107{
108 pointer_helper(const volatile void*);
109};
110
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700111yes_type NDNBOOST_TT_DECL is_pointer_tester(pointer_helper);
112no_type NDNBOOST_TT_DECL is_pointer_tester(...);
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700113
114template <bool>
115struct is_pointer_select
116 : public ::ndnboost::type_traits::false_result
117{
118};
119
120template <>
121struct is_pointer_select<false>
122{
123 template <typename T> struct result_
124 {
125 static T& make_t();
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700126 NDNBOOST_STATIC_CONSTANT(bool, value =
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700127 (::ndnboost::type_traits::ice_or<
128 (1 == sizeof(is_pointer_tester(make_t()))),
129 (1 == sizeof(type_traits::is_function_ptr_tester(make_t())))
130 >::value));
131 };
132};
133
134template <typename T>
135struct is_pointer_impl
136 : public is_pointer_select<
137 ::ndnboost::type_traits::ice_or<
138 ::ndnboost::is_reference<T>::value
139 , ::ndnboost::is_array<T>::value
140 >::value
141 >::template result_<T>
142{
143};
144
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700145NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pointer,void,false)
146#ifndef NDNBOOST_NO_CV_VOID_SPECIALIZATIONS
147NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pointer,void const,false)
148NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pointer,void volatile,false)
149NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pointer,void const volatile,false)
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700150#endif
151
152} // namespace detail
153
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700154NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_pointer,T,::ndnboost::detail::is_pointer_impl<T>::value)
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700155
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700156#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700157
158} // namespace ndnboost
159
Jeff Thompson2277ce52013-08-01 17:34:11 -0700160#include <ndnboost/type_traits/detail/bool_trait_undef.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700161
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700162#endif // NDNBOOST_TT_IS_POINTER_HPP_INCLUDED