Nektar++
traits.hpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: traits.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Vector type traits and tags.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_LIB_LIBUTILITES_SIMDLIB_TRAITS_H
36 #define NEKTAR_LIB_LIBUTILITES_SIMDLIB_TRAITS_H
37 
38 #include <type_traits>
39 
40 namespace tinysimd
41 {
42 
43 // Load tags
44 static constexpr struct is_aligned_t {} is_aligned{};
45 static constexpr struct is_not_aligned_t {} is_not_aligned{};
46 static constexpr struct is_not_reused_t {} is_not_reused{}; // streaming, skip cache
47 
48 // Check load tags
49 template <class T>
50 struct is_streaming : std::integral_constant
51  <
52  bool,
53  std::is_same<is_not_reused_t, typename std::remove_cv<T>::type>::value
54  > {};
55 
56 template <class T>
57 struct is_requiring_alignment : std::integral_constant
58  <
59  bool,
60  std::is_same<is_aligned_t, typename std::remove_cv<T>::type>::value ||
61  is_streaming<T>::value
62  > {};
63 
64 // Helper c++17 style
65 // template <class T>
66 // inline constexpr bool is_streaming_v = is_streaming<T>::value;
67 // template <class T>
68 // inline constexpr bool is_requiring_alignment_v = is_requiring_alignment<T>::value;
69 
70 
71 // has width type primary template
72 template <class T, class U = unsigned int>
73 struct has_width : std::false_type {};
74 // Specialization for U = unsigned int
75 template <class T>
76 struct has_width <T, decltype((void) T::width, 0u)> : std::true_type {};
77 
78 // has alignment type primary template
79 template <class T, class U = unsigned int>
80 struct has_alignment : std::false_type { };
81 // Specialization for U = unsigned int
82 template <class T>
83 struct has_alignment <T, decltype((void) T::alignment, 0u)> : std::true_type {};
84 
85 // Patch for missing std::void_t in pre c++17 compilers
86 template<class... Ts> struct make_void { typedef void type;};
87 template<class... Ts> using void_t = typename make_void<Ts...>::type;
88 
89 // Generic template handles types that have no nested ::scalarType member:
90 template <class, class = void_t<>>
91 struct has_scalarType : std::false_type { };
92 // Specialization recognizes types that do have a nested ::scalarType member:
93 template <class T>
94 struct has_scalarType<T, void_t<typename T::scalarType>> : std::true_type {};
95 
96 // If it quacks...
97 template <class T>
98 struct is_vector : std::integral_constant
99  <bool, has_alignment<T>::value && has_width<T>::value &&
100  has_scalarType<T>::value> {};
101 
102 // Helper c++17 style
103 // template <class T>
104 // inline constexpr bool is_vector_v = is_vector<T>::value;
105 
106 
107 // Generic template handles cases that are not vector type
108 template <class T, class = void>
109 struct is_vector_floating_point : std::false_type {};
110 
111 // Specialized template handles cases that are vector types
112 template <class T>
114  typename std::enable_if<
115  is_vector<T>::value>::type
116 > : std::integral_constant
117  <bool, std::is_floating_point<typename T::scalarType>::value> {};
118 
119 // Helper c++17 style
120 // template <class T>
121 // inline constexpr bool is_vector_floating_point_v = is_vector_floating_point<T>::value;
122 
123 // Generic template handles cases that are not vector type
124 template <class T, class = void>
125 struct is_vector_integral : std::false_type {};
126 
127 // Specialized template handles cases that are vector types
128 template <class T>
130  typename std::enable_if<
131  is_vector<T>::value>::type
132 > : std::integral_constant
133  <bool, std::is_integral<typename T::scalarType>::value> {};
134 
135 // Helper c++17 style
136 // template <class T>
137 // inline constexpr bool is_vector_floating_point_v = is_vector_floating_point<T>::value;
138 
139 } // namespace tinysimd
140 
141 #endif
static constexpr struct tinysimd::is_aligned_t is_aligned
static constexpr struct tinysimd::is_not_aligned_t is_not_aligned
static constexpr struct tinysimd::is_not_reused_t is_not_reused
typename make_void< Ts... >::type void_t
Definition: traits.hpp:87