Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 1 | |
| 2 | // (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000. |
| 3 | // Use, modification and distribution are subject to the Boost Software License, |
| 4 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 5 | // http://www.boost.org/LICENSE_1_0.txt). |
| 6 | // |
| 7 | // See http://www.boost.org/libs/type_traits for most recent version including documentation. |
| 8 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 9 | #ifndef NDNBOOST_TT_IS_POD_HPP_INCLUDED |
| 10 | #define NDNBOOST_TT_IS_POD_HPP_INCLUDED |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 11 | |
Jeff Thompson | 2277ce5 | 2013-08-01 17:34:11 -0700 | [diff] [blame] | 12 | #include <ndnboost/type_traits/config.hpp> |
| 13 | #include <ndnboost/type_traits/is_void.hpp> |
| 14 | #include <ndnboost/type_traits/is_scalar.hpp> |
| 15 | #include <ndnboost/type_traits/detail/ice_or.hpp> |
| 16 | #include <ndnboost/type_traits/intrinsics.hpp> |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 17 | |
| 18 | #include <cstddef> |
| 19 | |
| 20 | // should be the last #include |
Jeff Thompson | 2277ce5 | 2013-08-01 17:34:11 -0700 | [diff] [blame] | 21 | #include <ndnboost/type_traits/detail/bool_trait_def.hpp> |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 22 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 23 | #ifndef NDNBOOST_IS_POD |
| 24 | #define NDNBOOST_INTERNAL_IS_POD(T) false |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 25 | #else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 26 | #define NDNBOOST_INTERNAL_IS_POD(T) NDNBOOST_IS_POD(T) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 27 | #endif |
| 28 | |
| 29 | namespace ndnboost { |
| 30 | |
| 31 | // forward declaration, needed by 'is_pod_array_helper' template below |
| 32 | template< typename T > struct is_POD; |
| 33 | |
| 34 | namespace detail { |
| 35 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 36 | #ifndef NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 37 | |
| 38 | template <typename T> struct is_pod_impl |
| 39 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 40 | NDNBOOST_STATIC_CONSTANT( |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 41 | bool, value = |
| 42 | (::ndnboost::type_traits::ice_or< |
| 43 | ::ndnboost::is_scalar<T>::value, |
| 44 | ::ndnboost::is_void<T>::value, |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 45 | NDNBOOST_INTERNAL_IS_POD(T) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 46 | >::value)); |
| 47 | }; |
| 48 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 49 | #if !defined(NDNBOOST_NO_ARRAY_TYPE_SPECIALIZATIONS) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 50 | template <typename T, std::size_t sz> |
| 51 | struct is_pod_impl<T[sz]> |
| 52 | : public is_pod_impl<T> |
| 53 | { |
| 54 | }; |
| 55 | #endif |
| 56 | |
| 57 | #else |
| 58 | |
| 59 | template <bool is_array = false> |
| 60 | struct is_pod_helper |
| 61 | { |
| 62 | template <typename T> struct result_ |
| 63 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 64 | NDNBOOST_STATIC_CONSTANT( |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 65 | bool, value = |
| 66 | (::ndnboost::type_traits::ice_or< |
| 67 | ::ndnboost::is_scalar<T>::value, |
| 68 | ::ndnboost::is_void<T>::value, |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 69 | NDNBOOST_INTERNAL_IS_POD(T) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 70 | >::value)); |
| 71 | }; |
| 72 | }; |
| 73 | |
| 74 | template <bool b> |
| 75 | struct bool_to_yes_no_type |
| 76 | { |
| 77 | typedef ::ndnboost::type_traits::no_type type; |
| 78 | }; |
| 79 | |
| 80 | template <> |
| 81 | struct bool_to_yes_no_type<true> |
| 82 | { |
| 83 | typedef ::ndnboost::type_traits::yes_type type; |
| 84 | }; |
| 85 | |
| 86 | template <typename ArrayType> |
| 87 | struct is_pod_array_helper |
| 88 | { |
| 89 | enum { is_pod = ::ndnboost::is_POD<ArrayType>::value }; // MSVC workaround |
| 90 | typedef typename bool_to_yes_no_type<is_pod>::type type; |
| 91 | type instance() const; |
| 92 | }; |
| 93 | |
| 94 | template <typename T> |
| 95 | is_pod_array_helper<T> is_POD_array(T*); |
| 96 | |
| 97 | template <> |
| 98 | struct is_pod_helper<true> |
| 99 | { |
| 100 | template <typename T> struct result_ |
| 101 | { |
| 102 | static T& help(); |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 103 | NDNBOOST_STATIC_CONSTANT(bool, value = |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 104 | sizeof(is_POD_array(help()).instance()) == sizeof(::ndnboost::type_traits::yes_type) |
| 105 | ); |
| 106 | }; |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | template <typename T> struct is_pod_impl |
| 111 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 112 | NDNBOOST_STATIC_CONSTANT( |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 113 | bool, value = ( |
| 114 | ::ndnboost::detail::is_pod_helper< |
| 115 | ::ndnboost::is_array<T>::value |
| 116 | >::template result_<T>::value |
| 117 | ) |
| 118 | ); |
| 119 | }; |
| 120 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 121 | #endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 122 | |
| 123 | // the following help compilers without partial specialization support: |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 124 | NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,void,true) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 125 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 126 | #ifndef NDNBOOST_NO_CV_VOID_SPECIALIZATIONS |
| 127 | NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,void const,true) |
| 128 | NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,void volatile,true) |
| 129 | NDNBOOST_TT_AUX_BOOL_TRAIT_IMPL_SPEC1(is_pod,void const volatile,true) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 130 | #endif |
| 131 | |
| 132 | } // namespace detail |
| 133 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 134 | NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_pod,T,::ndnboost::detail::is_pod_impl<T>::value) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 135 | // is_POD is the old depricated name for this trait, do not use this as it may |
| 136 | // be removed in future without warning!! |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 137 | NDNBOOST_TT_AUX_BOOL_TRAIT_DEF1(is_POD,T,::ndnboost::is_pod<T>::value) |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 138 | |
| 139 | } // namespace ndnboost |
| 140 | |
Jeff Thompson | 2277ce5 | 2013-08-01 17:34:11 -0700 | [diff] [blame] | 141 | #include <ndnboost/type_traits/detail/bool_trait_undef.hpp> |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 142 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 143 | #undef NDNBOOST_INTERNAL_IS_POD |
Jeff Thompson | f7d4994 | 2013-08-01 16:47:40 -0700 | [diff] [blame] | 144 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 145 | #endif // NDNBOOST_TT_IS_POD_HPP_INCLUDED |