Turi Create  4.0
is_pod.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_IS_POD_HPP
7 #define TURI_IS_POD_HPP
8 #include <type_traits>
9 
10 namespace turi {
11 
12  /** \ingroup group_serialization
13  \brief Inheriting from this type will force the serializer
14  to treat the derived type as a POD type.
15  */
16  struct IS_POD_TYPE { };
17 
18  /**
19  * \ingroup group_serialization
20  *
21  * \brief Tests if T is a POD type
22  *
23  * gl_is_pod<T>::value is true if T is a POD type (as determined by
24  * boost::is_pod) or if T inherits from IS_POD_TYPE. gl_is_pod<T>::value
25  * is false otherwise.
26  */
27  template <typename T>
28  struct gl_is_pod{
29  // it is a pod and is not an integer since we have special handlings for integers
30  static constexpr bool value = std::is_scalar<T>::value ||
31  std::is_base_of<IS_POD_TYPE, T>::value;
32  /*
33  * BOOST_STATIC_CONSTANT(bool, value = (boost::type_traits::ice_or<
34  * boost::is_scalar<T>::value,
35  * boost::is_base_of<IS_POD_TYPE, T>::value
36  * >::value));
37  */
38 
39  // standard POD detection is no good because things which contain pointers
40  // are POD, but are not serializable
41  // (T is POD and T is not an integer of size >= 2)
42  /*BOOST_STATIC_CONSTANT(bool, value =
43  (
44  boost::type_traits::ice_and<
45  boost::is_pod<T>::value,
46  boost::type_traits::ice_not<
47  boost::type_traits::ice_and<
48  boost::is_integral<T>::value,
49  sizeof(T) >= 2
50  >::value
51  >::value
52  >::value
53  ));*/
54 
55  };
56 
57  /// \internal
58 
59  template <typename T>
61  static constexpr bool value = std::is_scalar<T>::value || gl_is_pod<T>::value;
62  };
63 }
64 
65 #endif
Inheriting from this type will force the serializer to treat the derived type as a POD type...
Definition: is_pod.hpp:16
Tests if T is a POD type.
Definition: is_pod.hpp:28