openPMD-api
TypeTraits.hpp
1 /* Copyright 2022 Franz Poeschel
2  *
3  * This file is part of openPMD-api.
4  *
5  * openPMD-api is free software: you can redistribute it and/or modify
6  * it under the terms of of either the GNU General Public License or
7  * the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * openPMD-api is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License and the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * and the GNU Lesser General Public License along with openPMD-api.
19  * If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #include "openPMD/auxiliary/UniquePtr.hpp"
25 
26 #include <array>
27 #include <cstddef> // size_t
28 #include <memory>
29 #include <vector>
30 
31 namespace openPMD::auxiliary
32 {
33 namespace detail
34 {
35  template <typename>
36  struct IsVector
37  {
38  static constexpr bool value = false;
39  };
40 
41  template <typename T>
42  struct IsVector<std::vector<T>>
43  {
44  static constexpr bool value = true;
45  };
46 
47  template <typename>
48  struct IsArray
49  {
50  static constexpr bool value = false;
51  };
52 
53  template <typename T, size_t n>
54  struct IsArray<std::array<T, n>>
55  {
56  static constexpr bool value = true;
57  };
58 
59  template <typename T>
60  struct IsPointer
61  {
62  constexpr static bool value = false;
63  };
64 
65  template <typename T>
66  struct IsPointer<T *>
67  {
68  constexpr static bool value = true;
69  using type = T;
70  };
71 
72  template <typename T>
73  struct IsPointer<std::shared_ptr<T>>
74  {
75  constexpr static bool value = true;
76  using type = T;
77  };
78 
79  template <typename T, typename Del>
80  struct IsPointer<std::unique_ptr<T, Del>>
81  {
82  constexpr static bool value = true;
83  using type = T;
84  };
85 
86  template <typename T>
88  {
89  constexpr static bool value = true;
90  using type = T;
91  };
92 } // namespace detail
93 
94 template <typename T>
95 inline constexpr bool IsVector_v = detail::IsVector<T>::value;
96 
97 template <typename T>
98 inline constexpr bool IsArray_v = detail::IsArray<T>::value;
99 
100 template <typename T>
101 inline constexpr bool IsPointer_v = detail::IsPointer<T>::value;
102 
103 template <typename T>
104 using IsPointer_t = typename detail::IsPointer<T>::type;
105 
114 template <typename T>
115 inline constexpr bool IsContiguousContainer_v = IsVector_v<T> || IsArray_v<T>;
116 
117 namespace
118 {
119  // see https://en.cppreference.com/w/cpp/language/if
120  template <typename>
121  inline constexpr bool dependent_false_v = false;
122 } // namespace
123 } // namespace openPMD::auxiliary
Unique Pointer class that uses a dynamic destructor type.
Definition: UniquePtr.hpp:86
Definition: TypeTraits.hpp:48
STL namespace.
Definition: Container.cpp:51
Definition: TypeTraits.hpp:60
Definition: TypeTraits.hpp:36
Definition: Date.cpp:28