Amesos2 - Direct Sparse Solver Interfaces Version of the Day
Amesos2_Meta.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Amesos2: Templated Direct Sparse Solver Package
4//
5// Copyright 2011 NTESS and the Amesos2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
24#ifndef AMESOS2_META_HPP
25#define AMESOS2_META_HPP
26
27#include <type_traits>
28
29#include "Amesos2_config.h"
30
31
32namespace Amesos2 {
33
34 namespace Meta {
35
43 // Meta-functions for boolean operators //
45
46 /* Must define these with the '_' suffix because they are
47 * otherwise keywords in C++
48 */
49
50 template <bool b1, bool b2>
51 struct or_ : public std::false_type {};
52
53 template <bool b>
54 struct or_<true,b> : public std::true_type {};
55
56 template <bool b>
57 struct or_<b,true> : public std::true_type {};
58
59
60 template <bool b1, bool b2>
61 struct and_ : public std::false_type {};
62
63 template <>
64 struct and_<true,true> : public std::true_type {};
65
66
67 template <bool b>
68 struct not_ {};
69
70 template <>
71 struct not_<true> : std::false_type {};
72
73 template <>
74 struct not_<false> : std::true_type {};
75
77 // A meta-programming type-list structure //
79
80 struct nil_t {}; // to denote an empty list
81
82 template <typename Head, typename Tail>
83 struct type_list {
84 typedef type_list<Head,Tail> type;
85 typedef Head head;
86 typedef Tail tail;
87 };
88
100 template <typename T1>
101 struct make_list1
102 : type_list<T1,nil_t>
103 { };
104
105 template <typename T1, typename T2>
106 struct make_list2
107 : type_list<T1,type_list<T2,nil_t> >
108 { };
109
110 template <typename T1, typename T2, typename T3>
111 struct make_list3
112 : type_list<T1, type_list<T2, type_list<T3,nil_t> > >
113 { };
114
115 template <typename T1, typename T2, typename T3, typename T4>
116 struct make_list4
117 : type_list<T1, type_list<T2, type_list<T3, type_list<T4,nil_t> > > >
118 { };
119
120 template <typename T1, typename T2, typename T3, typename T4, typename T5>
121 struct make_list5
122 : type_list<T1, type_list<T2, type_list<T3, type_list<T4, type_list<T5,nil_t> > > > >
123 { };
124
125 template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
126 struct make_list6
127 : type_list<T1, type_list<T2, type_list<T3, type_list<T4, type_list<T5, type_list<T6,nil_t> > > > > >
128 { };
129
130 /* More declarations for larger type lists may be added if necessary */
131
132
146 /* SR: We will not use external initialization for the static const types.
147 * Combined with template meta programming this fails in Intel compilers
148 * 11-13. Moving all the initializations inside the declarations.
149 */
150 template <typename list, typename elem>
151 struct type_list_contains {
152 static const bool value = std::conditional_t<
153 std::is_same_v<typename list::head, elem>,
154 std::true_type,
155 type_list_contains<typename list::tail,elem>
156 >::value;
157 };
158
159 // Base recursive case
160 template <typename elem>
161 struct type_list_contains<nil_t,elem> {
162 static const bool value = false;
163 };
164
167 } // end namespace Meta
168
169} // end namespace Amesos2
170
171#endif // AMESOS2_META_HPP