iterative-solver 0.0
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 <type_traits>
6
7namespace molpro::linalg::array {
9template <class... Ts>
10using void_t = void;
11
13template <class A, class = void_t<>>
14struct has_mapped_type : std::false_type {};
15
16template <class A>
17struct has_mapped_type<A, void_t<typename A::mapped_type>> : std::true_type {};
18
19template <class A>
21
22template <class T>
23constexpr bool is_sparse_v = has_mapped_type_v<T>;
24
26template <class A, bool = has_mapped_type_v<A>>
28 using type = typename A::value_type;
29};
30
31template <class A>
32struct mapped_or_value_type<A, true> {
33 using type = typename A::mapped_type;
34};
35
36template <class A>
38
40template <class T, typename = void>
41struct is_iterable : std::false_type {};
42
43template <class T>
44struct is_iterable<T, void_t<decltype(std::begin(std::declval<T>())), decltype(std::end(std::declval<T>())),
45 std::enable_if_t<!is_sparse_v<T>>>> : std::true_type {};
46
47template <class T>
48constexpr bool is_iterable_v = is_iterable<T>{};
49
51template <class T, typename = void>
52struct is_distributed : std::false_type {};
53
54template <class T>
55struct is_distributed<T, void_t<typename T::distributed_array>> : std::true_type {};
56
57template <class T>
59
61template <class T, typename = void>
62struct is_disk : std::false_type {};
63
64template <class T>
65struct is_disk<T, void_t<typename T::disk_array>> : std::true_type {};
66
67template <class T>
69
72
74template <class T, bool = is_iterable_v<T>, bool = is_sparse_v<T>, bool = is_distributed_v<T>, bool = is_disk_v<T>>
76 constexpr auto value() { return ArrayFamily::None; }
77};
78
79template <class T>
80struct array_family<T, true, false, false, false> {
81 constexpr auto value() { return ArrayFamily::Iterable; }
82};
83
84template <class T>
85struct array_family<T, false, true, false, false> {
86 constexpr auto value() { return ArrayFamily::Sparse; }
87};
88
89template <class T>
90struct array_family<T, false, false, true, false> {
91 constexpr auto value() { return ArrayFamily::Distributed; }
92};
93
94template <class T>
95struct array_family<T, false, false, true, true> {
96 constexpr auto value() { return ArrayFamily::DistributedDisk; }
97};
98
99template <class T>
101
102template <typename T>
103constexpr auto check_abs() {
104 using std::abs;
105 return abs(T{});
106}
107} // namespace molpro::linalg::array
108#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ARRAY_UTIL_TYPE_TRAITS_H
auto begin(Span< T > &x)
Definition: Span.h:84
Definition: ArrayHandler.h:22
constexpr bool is_sparse_v
Definition: type_traits.h:23
constexpr auto array_family_v
Definition: type_traits.h:100
constexpr bool has_mapped_type_v
Definition: type_traits.h:20
void void_t
Utility for metaprogramming that maps any types to void.
Definition: type_traits.h:10
constexpr bool is_disk_v
Definition: type_traits.h:68
constexpr bool is_iterable_v
Definition: type_traits.h:48
typename mapped_or_value_type< A >::type mapped_or_value_type_t
Definition: type_traits.h:37
constexpr auto check_abs()
Definition: type_traits.h:103
ArrayFamily
A tag to distinguish different families for array types, e.g. std::vector<> is iterable,...
Definition: type_traits.h:71
constexpr bool is_distributed_v
Definition: type_traits.h:58
constexpr auto value()
Definition: type_traits.h:91
constexpr auto value()
Definition: type_traits.h:96
constexpr auto value()
Definition: type_traits.h:86
constexpr auto value()
Definition: type_traits.h:81
Deduces which family an array type belongs to.
Definition: type_traits.h:75
constexpr auto value()
Definition: type_traits.h:76
checks that type name A::mapped_type exists
Definition: type_traits.h:14
Checks if class T has a tag marking it as a distributed disk array.
Definition: type_traits.h:62
Checks if class T has a tag marking it as a distributed array.
Definition: type_traits.h:52
Checks that class T can be iterated with std::begin and std::end, and is not sparse.
Definition: type_traits.h:41
typename A::mapped_type type
Definition: type_traits.h:33
Stores A::mapped_type or A::value_type as member type value, with former taking priority if both exis...
Definition: type_traits.h:27
typename A::value_type type
Definition: type_traits.h:28