]> git.donarmstrong.com Git - rsem.git/blob - boost/type_traits/msvc/remove_const.hpp
RSEM Source Codes
[rsem.git] / boost / type_traits / msvc / remove_const.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_CONST_HOLT_2004_0828
6 #define BOOST_TYPE_TRAITS_MSVC_REMOVE_CONST_HOLT_2004_0828
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_const_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<> //Const
28         struct remove_const_impl_typeof<false,false,true,false> {
29             template<typename T,typename ID>
30             struct inner {
31                 template<typename U>
32                 static msvc_register_type<U,ID> test(U const&(*)());
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<> //CV
43         struct remove_const_impl_typeof<false,false,true,true> {
44             template<typename T,typename ID>
45             struct inner {
46                 template<typename U>
47                 static msvc_register_type<U volatile,ID> test(U const volatile&(*)());
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<> //Const Pointer
58         struct remove_const_impl_typeof<true,false,true,false> {
59             template<typename T,typename ID>
60             struct inner {
61                 template<typename U>
62                 static msvc_register_type<U,ID> test(void(*)(U const[]));
63                 static msvc_register_type<T,ID> test(...);
64                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(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<> //CV Pointer
73         struct remove_const_impl_typeof<true,false,true,true> {
74             template<typename T,typename ID>
75             struct inner {
76                 template<typename U>
77                 static msvc_register_type<U volatile,ID> test(void(*)(U const 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 Array
88         struct remove_const_impl_typeof<false,true,true,false> {
89             template<typename T,typename ID>
90             struct inner {
91                 BOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0])));
92
93                 template<typename U>
94                 static msvc_register_type<U[value],ID> test(void(*)(U const[]));
95                 static msvc_register_type<T,ID> test(...);
96                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
97                 typedef typename msvc_extract_type<ID>::id2type::type type;
98             };
99             template<typename T>
100             struct transform_type {
101                 typedef T type;
102             };
103         };
104
105         template<> //CV Array
106         struct remove_const_impl_typeof<false,true,true,true> {
107             template<typename T,typename ID>
108             struct inner {
109                 BOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0])));
110
111                 template<typename U>
112                 static msvc_register_type<U volatile[value],ID> test(void(*)(U const volatile[]));
113                 static msvc_register_type<T,ID> test(...);
114                 BOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) ));
115                 typedef typename msvc_extract_type<ID>::id2type::type type;
116             };
117             template<typename T>
118             struct transform_type {
119                 typedef T type;
120             };
121         };
122
123     } //namespace detail
124
125     template<typename T>
126     struct remove_const {
127         typedef boost::detail::remove_const_impl_typeof<
128             boost::is_pointer<T>::value,
129             boost::is_array<T>::value,
130             boost::is_const<T>::value,
131             boost::is_volatile<T>::value
132         > remove_const_type;
133         typedef typename 
134             remove_const_type::template inner<
135                 typename remove_const_type::template transform_type<T>::type,
136                 remove_const<T>
137             >::type
138         type;
139         BOOST_MPL_AUX_LAMBDA_SUPPORT(1,remove_const,T)
140     };
141 }//namespace boost
142
143 #endif //BOOST_TYPE_TRAITS_MSVC_REMOVE_CONST_HOLT_2004_0828