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