Vc 1.4.5
SIMD Vector Classes for C++
 
Loading...
Searching...
No Matches
type_traits.h
1/* This file is part of the Vc library. {{{
2Copyright © 2013-2015 Matthias Kretz <kretz@kde.org>
3
4Redistribution and use in source and binary forms, with or without
5modification, are permitted provided that the following conditions are met:
6 * Redistributions of source code must retain the above copyright
7 notice, this list of conditions and the following disclaimer.
8 * Redistributions in binary form must reproduce the above copyright
9 notice, this list of conditions and the following disclaimer in the
10 documentation and/or other materials provided with the distribution.
11 * Neither the names of contributing organizations nor the
12 names of its contributors may be used to endorse or promote products
13 derived from this software without specific prior written permission.
14
15THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
19DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
26}}}*/
27
28#ifndef VC_TRAITS_TYPE_TRAITS_H_
29#define VC_TRAITS_TYPE_TRAITS_H_
30
31#include <type_traits>
32#include "decay.h"
33#include "has_no_allocated_data.h"
34#include "has_contiguous_storage.h"
35#include "is_functor_argument_immutable.h"
36#include "is_output_iterator.h"
37#include "is_index_sequence.h"
38#include "is_implicit_cast_allowed.h"
39
40namespace Vc_VERSIONED_NAMESPACE
41{
42// meta-programming helpers
43struct enable_if_default_type
44{
45 constexpr enable_if_default_type() {}
46};
47static constexpr enable_if_default_type nullarg;
48template <bool Test, typename T = enable_if_default_type> using enable_if = typename std::enable_if<Test, T>::type;
49
50template <bool B, class T, class F>
51using conditional_t = typename std::conditional<B, T, F>::type;
52
53template <class T>
54using remove_cvref_t =
55 typename std::remove_cv<typename std::remove_reference<T>::type>::type;
56
57namespace Traits
58{
59#include "has_subscript_operator.h"
60#include "has_multiply_operator.h"
61#include "has_addition_operator.h"
62#include "has_equality_operator.h"
63
64template<typename T> struct is_valid_vector_argument : public std::false_type {};
65
66template <> struct is_valid_vector_argument<double> : public std::true_type {};
67template <> struct is_valid_vector_argument<float> : public std::true_type {};
68template <> struct is_valid_vector_argument<int> : public std::true_type {};
69template <> struct is_valid_vector_argument<unsigned int> : public std::true_type {};
70template <> struct is_valid_vector_argument<short> : public std::true_type {};
71template <> struct is_valid_vector_argument<unsigned short> : public std::true_type {};
72
73template<typename T> struct is_simd_mask_internal : public std::false_type {};
74template<typename T> struct is_simd_vector_internal : public std::false_type {};
75template<typename T> struct is_simdarray_internal : public std::false_type {};
76template<typename T> struct is_simd_mask_array_internal : public std::false_type {};
77template<typename T> struct is_loadstoreflag_internal : public std::false_type {};
78
79template <typename T, bool = is_simd_vector_internal<T>::value> struct is_integral_internal;
80template <typename T, bool = is_simd_vector_internal<T>::value> struct is_floating_point_internal;
81template <typename T, bool = is_simd_vector_internal<T>::value> struct is_signed_internal;
82template <typename T, bool = is_simd_vector_internal<T>::value> struct is_unsigned_internal;
83
84template <typename T> struct is_integral_internal <T, false> : public std::is_integral <T> {};
85template <typename T> struct is_floating_point_internal<T, false> : public std::is_floating_point<T> {};
86template <typename T> struct is_signed_internal <T, false> : public std::is_signed <T> {};
87template <typename T> struct is_unsigned_internal <T, false> : public std::is_unsigned <T> {};
88
89template <typename V> struct is_integral_internal <V, true> : public std::is_integral <typename V::EntryType> {};
90template <typename V> struct is_floating_point_internal<V, true> : public std::is_floating_point<typename V::EntryType> {};
91template <typename V> struct is_signed_internal <V, true> : public std::is_signed <typename V::EntryType> {};
92template <typename V> struct is_unsigned_internal <V, true> : public std::is_unsigned <typename V::EntryType> {};
93
94template <typename T>
95struct is_arithmetic_internal
96 : public std::integral_constant<
97 bool,
98 (is_floating_point_internal<T>::value || is_integral_internal<T>::value)>
99{
100};
101
102template <class T, class = void>
103struct vector_size_internal : std::integral_constant<std::size_t, 0> {
104};
105template <class T>
106struct vector_size_internal<T, decltype((void)(T::size() > 0))>
107 : std::integral_constant<std::size_t, T::size()> {
108};
109
111
116template <typename T>
117struct is_simd_mask : public std::integral_constant<bool,
118 (is_simd_mask_internal<decay<T>>::value ||
119 is_simd_mask_array_internal<decay<T>>::value)>
120{
121};
122
127template <typename T>
129 : public std::integral_constant<bool,
130 (is_simd_vector_internal<decay<T>>::value ||
131 is_simdarray_internal<decay<T>>::value)>
132{
133};
134
136template <typename T>
137struct isSimdArray : public is_simdarray_internal<decay<T>>
138{
139};
140
142template <typename T>
143struct isSimdMaskArray : public is_simd_mask_array_internal<decay<T>>
144{
145};
146
148template <typename T> struct is_load_store_flag : public is_loadstoreflag_internal<decay<T>> {};
149
151template <typename T> struct is_atomic_simdarray_internal : public std::false_type {};
152template <typename T> using isAtomicSimdArray = is_atomic_simdarray_internal<decay<T>>;
153
155template <typename T> struct is_atomic_simd_mask_array_internal : public std::false_type {};
156template <typename T> using isAtomicSimdMaskArray = is_atomic_simd_mask_array_internal<decay<T>>;
157
162template <typename T> struct simd_vector_size : public vector_size_internal<decay<T>> {};
163
164template <typename T> struct is_integral : public is_integral_internal<decay<T>> {};
165template <typename T> struct is_floating_point : public is_floating_point_internal<decay<T>> {};
166template <typename T> struct is_arithmetic : public is_arithmetic_internal<decay<T>> {};
167template <typename T> struct is_signed : public is_signed_internal<decay<T>> {};
168template <typename T> struct is_unsigned : public is_unsigned_internal<decay<T>> {};
169
170template <typename T, bool IsSimdVector> struct scalar_type_internal { using type = T; };
171template <typename T> struct scalar_type_internal<T, true> { using type = typename T::EntryType; };
172template <typename T> using scalar_type = typename scalar_type_internal<decay<T>, is_simd_vector<T>::value>::type;
173
174} // namespace Traits
175} // namespace Vc
176
177#include "entry_type_of.h"
178
179#endif // VC_TRAITS_TYPE_TRAITS_H_
Identifies any possible SimdArray<T, N> type (independent of const/volatile or reference)
Identifies any possible SimdMaskArray<T, N> type (independent of const/volatile or reference)
Identifies any SIMD mask type (independent of implementation or whether it's SimdMaskArray<T,...
Identifies any SIMD vector type (independent of implementation or whether it's SimdArray<T,...
The value member will either be the number of SIMD vector entries or 0 if T is not a SIMD type.