Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 5 | #ifndef NDNBOOST_TYPE_TRAITS_MSVC_REMOVE_VOLATILE_HOLT_2004_0828 |
| 6 | #define NDNBOOST_TYPE_TRAITS_MSVC_REMOVE_VOLATILE_HOLT_2004_0828 |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 7 | |
| 8 | #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> |
| 13 | |
| 14 | namespace ndnboost { |
| 15 | namespace detail { |
| 16 | template<bool IsPointer,bool IsArray,bool IsConst,bool IsVolatile> |
| 17 | struct remove_volatile_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_volatile_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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 34 | NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (T(*)())(NULL) ) )); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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_volatile_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 const,ID> test(U const volatile&(*)()); |
| 48 | static msvc_register_type<T,ID> test(...); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 49 | NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (T(*)())(NULL) ) )); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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<> //Volatile Pointer |
| 58 | struct remove_volatile_impl_typeof<true,false,false,true> { |
| 59 | template<typename T,typename ID> |
| 60 | struct inner { |
| 61 | template<typename U> |
| 62 | static msvc_register_type<U,ID> test(void(*)(U volatile[])); |
| 63 | static msvc_register_type<T,ID> test(...); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 64 | NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) )); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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_volatile_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 const,ID> test(void(*)(U const volatile[])); |
| 78 | static msvc_register_type<T,ID> test(...); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 79 | NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) )); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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<> //Volatile Array |
| 88 | struct remove_volatile_impl_typeof<false,true,false,true> { |
| 89 | template<typename T,typename ID> |
| 90 | struct inner { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 91 | NDNBOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0]))); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 92 | |
| 93 | template<typename U> |
| 94 | static msvc_register_type<U[value],ID> test(void(*)(U volatile[])); |
| 95 | static msvc_register_type<T,ID> test(...); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 96 | NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) )); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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_volatile_impl_typeof<false,true,true,true> { |
| 107 | template<typename T,typename ID> |
| 108 | struct inner { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 109 | NDNBOOST_STATIC_CONSTANT(unsigned,value=(sizeof(T)/sizeof((*((T*)NULL))[0]))); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 110 | |
| 111 | template<typename U> |
| 112 | static msvc_register_type<U const[value],ID> test(void(*)(U const volatile[])); |
| 113 | static msvc_register_type<T,ID> test(...); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 114 | NDNBOOST_STATIC_CONSTANT(unsigned,register_test=sizeof(test( (void(*)(T))(NULL) ) )); |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 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_volatile { |
| 127 | typedef ndnboost::detail::remove_volatile_impl_typeof< |
| 128 | ndnboost::is_pointer<T>::value, |
| 129 | ndnboost::is_array<T>::value, |
| 130 | ndnboost::is_const<T>::value, |
| 131 | ndnboost::is_volatile<T>::value |
| 132 | > remove_volatile_type; |
| 133 | typedef typename |
| 134 | remove_volatile_type::template inner< |
| 135 | typename remove_volatile_type::template transform_type<T>::type, |
| 136 | remove_volatile<T> |
| 137 | >::type |
| 138 | type; |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 139 | NDNBOOST_MPL_AUX_LAMBDA_SUPPORT(1,remove_volatile,T) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 140 | }; |
| 141 | }//namespace ndnboost |
| 142 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 143 | #endif //NDNBOOST_TYPE_TRAITS_MSVC_REMOVE_VOLATILE_HOLT_2004_0828 |