]> git.donarmstrong.com Git - rsem.git/blob - boost/type_traits/msvc/remove_cv.hpp
RSEM Source Codes
[rsem.git] / boost / type_traits / msvc / remove_cv.hpp
1 // 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
5 #ifndef BOOST_TYPE_TRAITS_MSVC_REMOVE_CV_HOLT_2004_0901
6 #define BOOST_TYPE_TRAITS_MSVC_REMOVE_CV_HOLT_2004_0901
7
8 #include <boost/type_traits/msvc/typeof.hpp>
9 #include <boost/type_traits/is_volatile.hpp>
10 #include <boost/type_traits/is_const.hpp>
11 #include <boost/type_traits/is_pointer.hpp>
12 #include <boost/type_traits/is_array.hpp>
13
14 namespace boost {
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(...);
34                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (T(*)())(NULL) ) ));
35                 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(...);
49                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (T(*)())(NULL) ) ));
50                 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(...);
64                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (T(*)())(NULL) ) ));
65                 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(...);
79                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
80                 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(...);
94                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
95                 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(...);
109                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
110                 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 {
121                 BOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0])));
122
123                 template<typename U>
124                 static msvc_register_type<U[value],ID> test(void(*)(U volatile[]));
125                 static msvc_register_type<T,ID> test(...);
126                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
127                 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 {
138                 BOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0])));
139
140                 template<typename U>
141                 static msvc_register_type<U[value],ID> test(void(*)(U const[]));
142                 static msvc_register_type<T,ID> test(...);
143                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
144                 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 {
156                 BOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0])));
157
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(...);
161                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
162                 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 boost::detail::remove_cv_impl_typeof<
175             boost::is_pointer<T>::value,
176             boost::is_array<T>::value,
177             boost::is_const<T>::value,
178             boost::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;
186         BOOST_MPL_AUX_LAMBDA_SUPPORT(1,remove_cv,T)
187     };
188 }//namespace boost
189
190 #endif //BOOST_TYPE_TRAITS_MSVC_REMOVE_CV_HOLT_2004_0901