Amesos2 - Direct Sparse Solver Interfaces  Version of the Day
Amesos2_Meta.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Amesos2: Templated Direct Sparse Solver Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 //
42 // @HEADER
43 
58 #ifndef AMESOS2_META_HPP
59 #define AMESOS2_META_HPP
60 
61 #include <type_traits>
62 
63 #include "Amesos2_config.h"
64 
65 
66 namespace Amesos2 {
67 
68  namespace Meta {
69 
76  // Meta-functions for boolean operators //
79 
80  /* Must define these with the '_' suffix because they are
81  * otherwise keywords in C++
82  */
83 
84  template <bool b1, bool b2>
85  struct or_ : public std::false_type {};
86 
87  template <bool b>
88  struct or_<true,b> : public std::true_type {};
89 
90  template <bool b>
91  struct or_<b,true> : public std::true_type {};
92 
93 
94  template <bool b1, bool b2>
95  struct and_ : public std::false_type {};
96 
97  template <>
98  struct and_<true,true> : public std::true_type {};
99 
100 
101  template <bool b>
102  struct not_ {};
103 
104  template <>
105  struct not_<true> : std::false_type {};
106 
107  template <>
108  struct not_<false> : std::true_type {};
109 
111  // A meta-programming type-list structure //
113 
114  struct nil_t {}; // to denote an empty list
115 
116  template <typename Head, typename Tail>
117  struct type_list {
118  typedef type_list<Head,Tail> type;
119  typedef Head head;
120  typedef Tail tail;
121  };
122 
134  template <typename T1>
135  struct make_list1
136  : type_list<T1,nil_t>
137  { };
138 
139  template <typename T1, typename T2>
140  struct make_list2
141  : type_list<T1,type_list<T2,nil_t> >
142  { };
143 
144  template <typename T1, typename T2, typename T3>
145  struct make_list3
146  : type_list<T1, type_list<T2, type_list<T3,nil_t> > >
147  { };
148 
149  template <typename T1, typename T2, typename T3, typename T4>
150  struct make_list4
151  : type_list<T1, type_list<T2, type_list<T3, type_list<T4,nil_t> > > >
152  { };
153 
154  template <typename T1, typename T2, typename T3, typename T4, typename T5>
155  struct make_list5
156  : type_list<T1, type_list<T2, type_list<T3, type_list<T4, type_list<T5,nil_t> > > > >
157  { };
158 
159  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
160  struct make_list6
161  : type_list<T1, type_list<T2, type_list<T3, type_list<T4, type_list<T5, type_list<T6,nil_t> > > > > >
162  { };
163 
164  /* More declarations for larger type lists may be added if necessary */
165 
166 
180  /* SR: We will not use external initialization for the static const types.
181  * Combined with template meta programming this fails in Intel compilers
182  * 11-13. Moving all the initializations inside the declarations.
183  */
184  template <typename list, typename elem>
185  struct type_list_contains {
186  static const bool value = std::conditional_t<
187  std::is_same_v<typename list::head, elem>,
188  std::true_type,
189  type_list_contains<typename list::tail,elem>
190  >::value;
191  };
192 
193  // Base recursive case
194  template <typename elem>
195  struct type_list_contains<nil_t,elem> {
196  static const bool value = false;
197  };
198 
201  } // end namespace Meta
202 
203 } // end namespace Amesos2
204 
205 #endif // AMESOS2_META_HPP