blob: f3a0438e43012a39897abc20fdeceb7a3054e753 [file] [log] [blame]
Jeff Thompsonf7d49942013-08-01 16:47:40 -07001// Copyright (C) 2004 Peder Holt
2// Use, modification and distribution is subject to the Boost Software
3// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
4
Jeff Thompson3d613fd2013-10-15 15:39:04 -07005#ifndef NDNBOOST_TYPE_TRAITS_MSVC_REMOVE_CV_HOLT_2004_0901
6#define NDNBOOST_TYPE_TRAITS_MSVC_REMOVE_CV_HOLT_2004_0901
Jeff Thompsonf7d49942013-08-01 16:47:40 -07007
Jeff Thompson2277ce52013-08-01 17:34:11 -07008#include <ndnboost/type_traits/msvc/typeof.hpp>
9#include <ndnboost/type_traits/is_volatile.hpp>
10#include <ndnboost/type_traits/is_const.hpp>
11#include <ndnboost/type_traits/is_pointer.hpp>
12#include <ndnboost/type_traits/is_array.hpp>
Jeff Thompsonf7d49942013-08-01 16:47:40 -070013
14namespace ndnboost {
15 namespace detail {
16 template<bool IsPointer,bool IsArray,bool IsConst,bool IsVolatile>
17 struct remove_cv_impl_typeof {
18 template<typename T,typename ID>
19 struct inner {
20 typedef T type;
21 };
22 template<typename T>
23 struct transform_type {
24 typedef T type;
25 };
26 };
27 template<> //Volatile
28 struct remove_cv_impl_typeof<false,false,false,true> {
29 template<typename T,typename ID>
30 struct inner {
31 template<typename U>
32 static msvc_register_type<U,ID> test(U volatile&(*)());
33 static msvc_register_type<T,ID> test(...);
Jeff Thompson3d613fd2013-10-15 15:39:04 -070034 NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (T(*)())(NULL) ) ));
Jeff Thompsonf7d49942013-08-01 16:47:40 -070035 typedef typename msvc_extract_type<ID>::id2type::type type;
36 };
37 template<typename T>
38 struct transform_type {
39 typedef T& type;
40 };
41 };
42 template<> //Const
43 struct remove_cv_impl_typeof<false,false,true,false> {
44 template<typename T,typename ID>
45 struct inner {
46 template<typename U>
47 static msvc_register_type<U,ID> test(U const&(*)());
48 static msvc_register_type<T,ID> test(...);
Jeff Thompson3d613fd2013-10-15 15:39:04 -070049 NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (T(*)())(NULL) ) ));
Jeff Thompsonf7d49942013-08-01 16:47:40 -070050 typedef typename msvc_extract_type<ID>::id2type::type type;
51 };
52 template<typename T>
53 struct transform_type {
54 typedef T& type;
55 };
56 };
57 template<> //CV
58 struct remove_cv_impl_typeof<false,false,true,true> {
59 template<typename T,typename ID>
60 struct inner {
61 template<typename U>
62 static msvc_register_type<U,ID> test(U const volatile&(*)());
63 static msvc_register_type<T,ID> test(...);
Jeff Thompson3d613fd2013-10-15 15:39:04 -070064 NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (T(*)())(NULL) ) ));
Jeff Thompsonf7d49942013-08-01 16:47:40 -070065 typedef typename msvc_extract_type<ID>::id2type::type type;
66 };
67 template<typename T>
68 struct transform_type {
69 typedef T& type;
70 };
71 };
72 template<> //Volatile Pointer
73 struct remove_cv_impl_typeof<true,false,false,true> {
74 template<typename T,typename ID>
75 struct inner {
76 template<typename U>
77 static msvc_register_type<U,ID> test(void(*)(U volatile[]));
78 static msvc_register_type<T,ID> test(...);
Jeff Thompson3d613fd2013-10-15 15:39:04 -070079 NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
Jeff Thompsonf7d49942013-08-01 16:47:40 -070080 typedef typename msvc_extract_type<ID>::id2type::type type;
81 };
82 template<typename T>
83 struct transform_type {
84 typedef T type[];
85 };
86 };
87 template<> //Const Pointer
88 struct remove_cv_impl_typeof<true,false,true,false> {
89 template<typename T,typename ID>
90 struct inner {
91 template<typename U>
92 static msvc_register_type<U,ID> test(void(*)(U const[]));
93 static msvc_register_type<T,ID> test(...);
Jeff Thompson3d613fd2013-10-15 15:39:04 -070094 NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
Jeff Thompsonf7d49942013-08-01 16:47:40 -070095 typedef typename msvc_extract_type<ID>::id2type::type type;
96 };
97 template<typename T>
98 struct transform_type {
99 typedef T type[];
100 };
101 };
102 template<> //CV Pointer
103 struct remove_cv_impl_typeof<true,false,true,true> {
104 template<typename T,typename ID>
105 struct inner {
106 template<typename U>
107 static msvc_register_type<U,ID> test(void(*)(U const volatile[]));
108 static msvc_register_type<T,ID> test(...);
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700109 NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700110 typedef typename msvc_extract_type<ID>::id2type::type type;
111 };
112 template<typename T>
113 struct transform_type {
114 typedef T type[];
115 };
116 };
117 template<> //Volatile Array
118 struct remove_cv_impl_typeof<false,true,false,true> {
119 template<typename T,typename ID>
120 struct inner {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700121 NDNBOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0])));
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700122
123 template<typename U>
124 static msvc_register_type<U[value],ID> test(void(*)(U volatile[]));
125 static msvc_register_type<T,ID> test(...);
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700126 NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700127 typedef typename msvc_extract_type<ID>::id2type::type type;
128 };
129 template<typename T>
130 struct transform_type {
131 typedef T type;
132 };
133 };
134 template<> //Const Array
135 struct remove_cv_impl_typeof<false,true,true,false> {
136 template<typename T,typename ID>
137 struct inner {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700138 NDNBOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0])));
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700139
140 template<typename U>
141 static msvc_register_type<U[value],ID> test(void(*)(U const[]));
142 static msvc_register_type<T,ID> test(...);
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700143 NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700144 typedef typename msvc_extract_type<ID>::id2type::type type;
145 };
146 template<typename T>
147 struct transform_type {
148 typedef T type;
149 };
150 };
151
152 template<> //CV Array
153 struct remove_cv_impl_typeof<false,true,true,true> {
154 template<typename T,typename ID>
155 struct inner {
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700156 NDNBOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0])));
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700157
158 template<typename U>
159 static msvc_register_type<U[value],ID> test(void(*)(U const volatile[]));
160 static msvc_register_type<T,ID> test(...);
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700161 NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700162 typedef typename msvc_extract_type<ID>::id2type::type type;
163 };
164 template<typename T>
165 struct transform_type {
166 typedef T type;
167 };
168 };
169
170 } //namespace detail
171
172 template<typename T>
173 struct remove_cv {
174 typedef ndnboost::detail::remove_cv_impl_typeof<
175 ndnboost::is_pointer<T>::value,
176 ndnboost::is_array<T>::value,
177 ndnboost::is_const<T>::value,
178 ndnboost::is_volatile<T>::value
179 > remove_cv_type;
180 typedef typename
181 remove_cv_type::template inner<
182 typename remove_cv_type::template transform_type<T>::type,
183 remove_cv<T>
184 >::type
185 type;
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700186 NDNBOOST_MPL_AUX_LAMBDA_SUPPORT(1,remove_cv,T)
Jeff Thompsonf7d49942013-08-01 16:47:40 -0700187 };
188}//namespace ndnboost
189
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700190#endif //NDNBOOST_TYPE_TRAITS_MSVC_REMOVE_CV_HOLT_2004_0901