Nektar++
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} // namespace details
131
132// If it quacks...
133template <class T>
135 : std::integral_constant<bool, details::has_alignment<T>::value &&
136 details::has_width<T>::value &&
137 details::has_scalarType<T>::value>
138{
139};
140
141// Helper c++17 style
142template <class T> inline constexpr bool is_vector_v = is_vector<T>::value;
143
144// Generic template handles cases that are not vector type
145template <class T, class = void>
146struct is_vector_floating_point : std::false_type
147{
148};
149
150// Specialized template handles cases that are vector types
151template <class T>
153 typename std::enable_if<is_vector_v<T>>::type>
154 : std::integral_constant<bool,
155 std::is_floating_point_v<typename T::scalarType>>
156{
157};
158
159// Helper c++17 style
160template <class T>
161inline constexpr bool is_vector_floating_point_v =
163
164// Generic template handles cases that are not vector type
165template <class T, class = void> struct is_vector_integral : std::false_type
166{
167};
168
169// Specialized template handles cases that are vector types
170template <class T>
171struct is_vector_integral<T, typename std::enable_if<is_vector_v<T>>::type>
172 : std::integral_constant<bool, std::is_integral_v<typename T::scalarType>>
173{
174};
175
176// Helper c++17 style
177template <class T>
179
180} // namespace tinysimd
181
182#endif
STL namespace.
typename make_void< Ts... >::type void_t
Definition: traits.hpp:119
constexpr bool is_vector_floating_point_v
Definition: traits.hpp:161
constexpr bool is_vector_integral_v
Definition: traits.hpp:178
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:142
constexpr bool is_streaming_v
Definition: traits.hpp:86
constexpr bool is_requiring_alignment_v
Definition: traits.hpp:88