iterative-solver 0.0
 
Loading...
Searching...
No Matches
type_traits.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_TYPE_TRAITS_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_TYPE_TRAITS_H
3#include <cmath>
4#include <cstdlib>
5#include <iterator>
6#include <type_traits>
7
8namespace molpro::linalg::array {
10template <class... Ts>
11using void_t = void;
12
14template <class A, class = void_t<>>
15struct has_mapped_type : std::false_type {};
16
17template <class A>
18struct has_mapped_type<A, void_t<typename A::mapped_type>> : std::true_type {};
19
20template <class A>
22
23template <class T>
24constexpr bool is_sparse_v = has_mapped_type_v<T>;
25
27template <class A, bool = has_mapped_type_v<A>>
29 using type = typename A::value_type;
30};
31
32template <class A>
33struct mapped_or_value_type<A, true> {
34 using type = typename A::mapped_type;
35};
36
37template <class A>
39
41template <class T, typename = void>
42struct is_iterable : std::false_type {};
43
44template <class T>
45struct is_iterable<T, void_t<decltype(std::begin(std::declval<T>())), decltype(std::end(std::declval<T>())),
46 std::enable_if_t<!is_sparse_v<T>>>> : std::true_type {};
47
48template <class T>
49constexpr bool is_iterable_v = is_iterable<T>{};
50
52template <class T, typename = void>
53struct is_contiguous : std::false_type {};
54
55template <class T>
57 T, void_t<decltype(std::size(std::declval<const T&>())),
58 std::enable_if_t<std::is_pointer_v<decltype(std::data(std::declval<const T&>()))> && !is_sparse_v<T>>>>
59 : std::true_type {};
60
61template <class T>
63
65template <class T, typename = void>
66struct is_distributed : std::false_type {};
67
68template <class T>
69struct is_distributed<T, void_t<typename T::distributed_array>> : std::true_type {};
70
71template <class T>
73
75template <class T, typename = void>
76struct is_disk : std::false_type {};
77
78template <class T>
79struct is_disk<T, void_t<typename T::disk_array>> : std::true_type {};
80
81template <class T>
83
86
88template <class T, bool = is_iterable_v<T>, bool = is_sparse_v<T>, bool = is_distributed_v<T>, bool = is_disk_v<T>>
90 constexpr auto value() { return ArrayFamily::None; }
91};
92
93template <class T>
94struct array_family<T, true, false, false, false> {
95 constexpr auto value() { return ArrayFamily::Iterable; }
96};
97
98template <class T>
99struct array_family<T, false, true, false, false> {
100 constexpr auto value() { return ArrayFamily::Sparse; }
101};
102
103template <class T>
104struct array_family<T, false, false, true, false> {
105 constexpr auto value() { return ArrayFamily::Distributed; }
106};
107
108template <class T>
109struct array_family<T, false, false, true, true> {
110 constexpr auto value() { return ArrayFamily::DistributedDisk; }
111};
112
113template <class T>
115
116template <typename T>
117constexpr auto check_abs() {
118 using std::abs;
119 return abs(T{});
120}
121} // namespace molpro::linalg::array
122#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_TYPE_TRAITS_H
auto begin(Span< T > &x)
Definition Span.h:90
Definition ArrayHandler.h:19
constexpr bool is_sparse_v
Definition type_traits.h:24
constexpr auto array_family_v
Definition type_traits.h:114
constexpr bool has_mapped_type_v
Definition type_traits.h:21
void void_t
Utility for metaprogramming that maps any types to void.
Definition type_traits.h:11
constexpr bool is_disk_v
Definition type_traits.h:82
constexpr bool is_iterable_v
Definition type_traits.h:49
typename mapped_or_value_type< A >::type mapped_or_value_type_t
Definition type_traits.h:38
constexpr auto check_abs()
Definition type_traits.h:117
constexpr bool is_contiguous_v
Definition type_traits.h:62
ArrayFamily
A tag to distinguish different families for array types, e.g. std::vector<> is iterable,...
Definition type_traits.h:85
constexpr bool is_distributed_v
Definition type_traits.h:72
constexpr auto value()
Definition type_traits.h:105
constexpr auto value()
Definition type_traits.h:110
constexpr auto value()
Definition type_traits.h:100
Deduces which family an array type belongs to.
Definition type_traits.h:89
constexpr auto value()
Definition type_traits.h:90
checks that type name A::mapped_type exists
Definition type_traits.h:15
Checks that class T holds its elements in contiguous memory, which std::data() points to,...
Definition type_traits.h:53
Checks if class T has a tag marking it as a distributed disk array.
Definition type_traits.h:76
Checks if class T has a tag marking it as a distributed array.
Definition type_traits.h:66
Checks that class T can be iterated with std::begin and std::end, and is not sparse.
Definition type_traits.h:42
typename A::mapped_type type
Definition type_traits.h:34
Stores A::mapped_type or A::value_type as member type value, with former taking priority if both exis...
Definition type_traits.h:28
typename A::value_type type
Definition type_traits.h:29