remove \r
[extl.git] / extl / type / traits / remove_const.h
blobdef6fb6f65903f66be19a7a2bb7ea88148c0aa30
1 /* ///////////////////////////////////////////////////////////////////////
2 * File: remove_const.h
4 * Created: 08.02.07
5 * Updated: 08.07.09
7 * Brief: remove_const traits
9 * [<Home>]
10 * Copyright (c) 2008-2020, Waruqi All rights reserved.
11 * //////////////////////////////////////////////////////////////////// */
12 #ifndef EXTL_TYPE_TRAITS_REMOVE_CONST_H
13 #define EXTL_TYPE_TRAITS_REMOVE_CONST_H
15 #ifndef EXTL_TYPE_TRAITS_REMOVE_CONST_SUPPORT
16 # error extl::remove_const is not supported by current compiler.
17 #endif
19 /* ///////////////////////////////////////////////////////////////////////
20 * Includes
22 #include "prefix.h"
24 #ifdef EXTL_TYPE_TRAITS_IS_PTR_SUPPORT
25 # include "is_ptr.h"
26 #endif
28 #ifdef EXTL_TYPE_TRAITS_IS_CONST_SUPPORT
29 # include "is_const.h"
30 #endif
32 #ifdef EXTL_TYPE_TRAITS_IS_VOLATILE_SUPPORT
33 # include "is_volatile.h"
34 #endif
36 #ifdef EXTL_TYPE_TRAITS_IS_ARRAY_SUPPORT
37 # include "is_array.h"
38 #endif
40 // only for VC 6.0,7.0,7.1
41 #if defined(EXTL_TYPE_TRAITS_TYPE_BUFFER_SUPPORT)
42 # include "detail/type_buffer.h"
43 #endif
45 /* ///////////////////////////////////////////////////////////////////////
46 * Macros
48 #define EXTL_REMOVE_CONST(src_type) EXTL_MODIFY_TYPE(remove_const, src_type)
50 /* ///////////////////////////////////////////////////////////////////////
51 * ::extl namespace
53 EXTL_BEGIN_NAMESPACE
55 #ifdef EXTL_TYPE_TRAITS_SUPPORT
57 # ifdef EXTL_TEMPLATE_PARTIAL_SPEC_SUPPORT
59 EXTL_TYPE_TRAIT_DEF_1(remove_const_impl, T)
60 EXTL_TYPE_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T, remove_const_impl, T*, T)
61 EXTL_TYPE_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T, remove_const_impl, const T*, T)
62 EXTL_TYPE_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T, remove_const_impl, volatile T*, volatile T)
63 EXTL_TYPE_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T, remove_const_impl, const volatile T*, volatile T)
65 EXTL_TYPE_TRAIT_DEF_1(remove_const, typename_type_k remove_const_impl<T*>::type)
66 EXTL_TYPE_TRAIT_PARTIAL_SPEC_1_1(typename_param_k T, remove_const, T&, T&)
68 # ifdef EXTL_TEMPLATE_PARTIAL_SPEC_ARRAY_TYPE_SUPPORT
69 EXTL_TYPE_TRAIT_PARTIAL_SPEC_TO_ARRAY_1_2(typename_param_k T, e_size_t N, remove_const, T const[N], T type[N])
70 EXTL_TYPE_TRAIT_PARTIAL_SPEC_TO_ARRAY_1_2(typename_param_k T, e_size_t N, remove_const, T const volatile [N], T volatile type[N])
71 # endif
73 # elif EXTL_WORKAROUND_MSVC(<=, 1300)
74 /* //////////////////////////////////////////////////////////////////// */
75 template< e_bool_t is_ptr, e_bool_t is_array, e_bool_t is_const, e_bool_t is_volatile >
76 struct remove_const_helper
78 template< typename_param_k T , typename_param_k ID >
79 struct result
81 typedef T type;
83 template< typename_param_k T >
84 struct transform_type
86 typedef T type;
89 EXTL_TEMPLATE_SPECIALISATION // const
90 struct remove_const_helper< e_false_v, e_false_v, e_true_v , e_false_v >
92 template< typename_param_k T, typename_param_k ID >
93 struct result
95 template< typename_param_k U >
96 static save_type<U, ID> test(U const&(*)());
97 static save_type<T, ID> test(...);
98 EXTL_STATIC_MEMBER_CONST(e_bool_t, value = sizeof( test( (T(*)())(NULL) ) ));
99 typedef typename_type_k type_buffer<ID>::result::type type;
101 template< typename_param_k T >
102 struct transform_type
104 typedef T& type; // exclude const&
108 EXTL_TEMPLATE_SPECIALISATION // cv
109 struct remove_const_helper< e_false_v, e_false_v, e_true_v , e_true_v >
111 template< typename_param_k T, typename_param_k ID >
112 struct result
114 template< typename_param_k U >
115 static save_type<U volatile, ID> test(U const volatile&(*)());
116 static save_type<T, ID> test(...);
117 EXTL_STATIC_MEMBER_CONST(e_bool_t, value = sizeof( test( (T(*)())(NULL) ) ));
118 typedef typename_type_k type_buffer<ID>::result::type type;
120 template< typename_param_k T >
121 struct transform_type
123 typedef T& type; // exclude const&
127 EXTL_TEMPLATE_SPECIALISATION // const ptr
128 struct remove_const_helper< e_true_v, e_false_v, e_true_v , e_false_v >
130 template< typename_param_k T, typename_param_k ID >
131 struct result
133 template< typename_param_k U >
134 static save_type<U, ID> test(void(*)(U const[]));
135 static save_type<T, ID> test(...);
136 EXTL_STATIC_MEMBER_CONST(e_bool_t, value = sizeof( test( (void(*)(T))(NULL) ) ));
137 typedef typename_type_k type_buffer<ID>::result::type type;
139 template< typename_param_k T >
140 struct transform_type
142 typedef T type[];
146 EXTL_TEMPLATE_SPECIALISATION // cv ptr
147 struct remove_const_helper< e_true_v, e_false_v, e_true_v , e_true_v >
149 template< typename_param_k T, typename_param_k ID >
150 struct result
152 template< typename_param_k U >
153 static save_type<U volatile, ID> test(void(*)(U const volatile[]));
154 static save_type<T, ID> test(...);
155 EXTL_STATIC_MEMBER_CONST(e_bool_t, value = sizeof( test( (void(*)(T))(NULL) ) ));
156 typedef typename_type_k type_buffer<ID>::result::type type;
158 template< typename_param_k T >
159 struct transform_type
161 typedef T type[];
165 EXTL_TEMPLATE_SPECIALISATION // const array
166 struct remove_const_helper< e_false_v, e_true_v, e_true_v , e_false_v >
168 template< typename_param_k T, typename_param_k ID >
169 struct result
171 EXTL_STATIC_MEMBER_CONST(e_size_t, num = (sizeof(T)/sizeof((*((T*)NULL))[0])) );
173 template< typename_param_k U >
174 static save_type<U[num], ID> test(void(*)(U const[]));
175 static save_type<T, ID> test(...);
176 EXTL_STATIC_MEMBER_CONST(e_bool_t, value = sizeof( test( (void(*)(T))(NULL) ) ));
177 typedef typename_type_k type_buffer<ID>::result::type type;
179 template< typename_param_k T >
180 struct transform_type
182 typedef T type;
186 EXTL_TEMPLATE_SPECIALISATION // cv array
187 struct remove_const_helper< e_false_v, e_true_v, e_true_v , e_true_v >
189 template< typename_param_k T, typename_param_k ID >
190 struct result
192 EXTL_STATIC_MEMBER_CONST(e_size_t, num = (sizeof(T)/sizeof((*((T*)NULL))[0])) );
194 template< typename_param_k U >
195 static save_type<U volatile[num], ID> test(void(*)(U const volatile[]));
196 static save_type<T, ID> test(...);
197 EXTL_STATIC_MEMBER_CONST(e_bool_t, value = sizeof( test( (void(*)(T))(NULL) ) ));
198 typedef typename_type_k type_buffer<ID>::result::type type;
200 template< typename_param_k T >
201 struct transform_type
203 typedef T type;
207 template< typename_param_k T>
208 struct remove_const_impl
210 typedef remove_const_helper < (is_ptr<T>::value)
211 , (is_array<T>::value)
212 , (is_const<T>::value)
213 , (is_volatile<T>::value)
214 > remove_const_type;
216 typedef typename_type_k remove_const_type::template_qual_k result<
217 typename_type_k remove_const_type::template_qual_k transform_type<T>::type
218 , remove_const_impl<T>
219 >::type type;
223 EXTL_TYPE_TRAIT_DEF_1(remove_const, typename_type_k remove_const_impl<T>::type)
225 # endif
227 /* ///////////////////////////////////////////////////////////////////////
228 * Unit-testing
230 # ifdef EXTL_TYPE_TRAITS_TEST_ENABLE
231 # include "unit_test/remove_const_test.h"
232 # endif
233 #endif
234 /* ///////////////////////////////////////////////////////////////////////
235 * ::extl namespace
237 EXTL_END_NAMESPACE
239 /* //////////////////////////////////////////////////////////////////// */
240 #endif /* EXTL_TYPE_TRAITS_REMOVE_CONST_H */
241 /* //////////////////////////////////////////////////////////////////// */