Nektar++
Loading...
Searching...
No Matches
traits.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: traits.hpp
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
40namespace tinysimd
41{
42
43// Load tags
44static constexpr struct is_aligned_t
45{
47static constexpr struct is_not_aligned_t
48{
50static constexpr struct is_not_reused_t
51{
52} is_not_reused{}; // streaming, skip cache
53
54// Check load tags
55template <class T>
57 : std::integral_constant<
58 bool,
59 std::is_same_v<is_aligned_t, typename std::remove_cv<T>::type> ||
60 std::is_same_v<is_not_aligned_t,
61 typename std::remove_cv<T>::type> ||
62 std::is_same_v<is_not_reused_t, typename std::remove_cv<T>::type>>
63{
64};
65
66template <class T>
68 : std::integral_constant<
69 bool,
70 std::is_same_v<is_not_reused_t, typename std::remove_cv<T>::type>>
71{
72};
73
74template <class T>
76 : std::integral_constant<
77 bool,
78 std::is_same_v<is_aligned_t, typename std::remove_cv<T>::type> ||
79 is_streaming<T>::value>
80{
81};
82
83// Helper c++17 style
84template <class T> inline constexpr bool is_load_tag_v = is_load_tag<T>::value;
85template <class T>
86inline constexpr bool is_streaming_v = is_streaming<T>::value;
87template <class T>
88inline constexpr bool is_requiring_alignment_v =
90
91namespace details
92{
93// has width type primary template
94template <class T, class U = unsigned int> struct has_width : std::false_type
95{
96};
97// Specialization for U = unsigned int
98template <class T>
99struct has_width<T, decltype((void)T::width, 0u)> : std::true_type
100{
101};
102
103// has alignment type primary template
104template <class T, class U = unsigned int>
105struct has_alignment : std::false_type
106{
107};
108// Specialization for U = unsigned int
109template <class T>
110struct has_alignment<T, decltype((void)T::alignment, 0u)> : std::true_type
111{
112};
113
114// Patch for missing std::void_t in pre C++17 compilers
115template <class... Ts> struct make_void
116{
117 typedef void type;
118};
119template <class... Ts> using void_t = typename make_void<Ts...>::type;
120
121// Generic template handles types that have no nested ::scalarType member:
122template <class, class = void_t<>> struct has_scalarType : std::false_type
123{
124};
125// Specialization recognizes types that do have a nested ::scalarType member:
126template <class T>
127struct has_scalarType<T, void_t<typename T::scalarType>> : std::true_type
128{
129};
130
131// Generic template handles types that have no nested ::scalarIndexType member:
132template <class, class = void_t<>> struct has_scalarIndexType : std::false_type
133{
134};
135// Specialization recognizes types that do have a nested ::scalarIndexType
136// member:
137template <class T>
138struct has_scalarIndexType<T, void_t<typename T::scalarIndexType>>
139 : std::true_type
140{
141};
142} // namespace details
143
144// If it quacks...
145template <class T>
147 : std::integral_constant<bool, details::has_alignment<T>::value &&
148 details::has_width<T>::value &&
149 details::has_scalarType<T>::value>
150{
151};
152
153// Helper c++17 style
154template <class T> inline constexpr bool is_vector_v = is_vector<T>::value;
155
156// Generic template handles cases that are not vector type
157template <class T, class = void>
158struct is_vector_floating_point : std::false_type
159{
160};
161
162// Specialized template handles cases that are vector types
163template <class T>
165 typename std::enable_if<is_vector_v<T>>::type>
166 : std::integral_constant<bool,
167 std::is_floating_point_v<typename T::scalarType>>
168{
169};
170
171// Helper c++17 style
172template <class T>
173inline constexpr bool is_vector_floating_point_v =
175
176// Generic template handles cases that are not vector type
177template <class T, class = void> struct is_vector_integral : std::false_type
178{
179};
180
181// Specialized template handles cases that are vector types
182template <class T>
183struct is_vector_integral<T, typename std::enable_if<is_vector_v<T>>::type>
184 : std::integral_constant<bool, std::is_integral_v<typename T::scalarType>>
185{
186};
187
188// Helper c++17 style
189template <class T>
191
192} // namespace tinysimd
193
194#endif
STL namespace.
typename make_void< Ts... >::type void_t
Definition traits.hpp:119
constexpr bool is_vector_floating_point_v
Definition traits.hpp:173
constexpr bool is_vector_integral_v
Definition traits.hpp:190
constexpr bool is_load_tag_v
Definition traits.hpp:84
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
constexpr bool is_vector_v
Definition traits.hpp:154
constexpr bool is_streaming_v
Definition traits.hpp:86
constexpr bool is_requiring_alignment_v
Definition traits.hpp:88