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 "Amesos2_config.h"
62 
63 
64 namespace Amesos2 {
65 
66  namespace Meta {
67 
74  /* SR: We will not use external initialization for the static const types.
75  * Combined with template meta programming this fails in Intel compilers
76  * 11-13. Moving all the initializations inside the declarations.
77  */
78  template <class T, T val>
79  struct integral_constant
80  {
81  typedef integral_constant<T, val> type;
82  typedef T value_type;
83  static const T value = val;
84  };
85 
86 
87  typedef integral_constant<bool, true> true_type;
88  typedef integral_constant<bool, false> false_type;
89 
91  // Testing the same'ness of two types //
93 
97  template <typename, typename>
98  struct is_same : public false_type
99  {};
100 
101  template <typename T>
102  struct is_same<T,T> : public true_type
103  {};
104 
105 
106 
108  // Meta-functions for boolean operators //
110 
111  /* Must define these with the '_' suffix because they are
112  * otherwise keywords in C++
113  */
114 
115  template <bool b1, bool b2>
116  struct or_ : public false_type {};
117 
118  template <bool b>
119  struct or_<true,b> : public true_type {};
120 
121  template <bool b>
122  struct or_<b,true> : public true_type {};
123 
124 
125  template <bool b1, bool b2>
126  struct and_ : public false_type {};
127 
128  template <>
129  struct and_<true,true> : public true_type {};
130 
131 
132  template <bool b>
133  struct not_ {};
134 
135  template <>
136  struct not_<true> : false_type {};
137 
138  template <>
139  struct not_<false> : true_type {};
140 
141 
143  // Evaluating to a conditional type //
145 
146  template <bool B, typename T1, typename T2>
147  struct if_then_else {};
148 
149  template <typename T1, typename T2>
150  struct if_then_else<true, T1, T2> {
151  typedef T1 type;
152  };
153 
154  template <typename T1, typename T2>
155  struct if_then_else<false, T1, T2> {
156  typedef T2 type;
157  };
158 
159 
161  // A meta-programming type-list structure //
163 
164  struct nil_t {}; // to denote an empty list
165 
166  template <typename Head, typename Tail>
167  struct type_list {
168  typedef type_list<Head,Tail> type;
169  typedef Head head;
170  typedef Tail tail;
171  };
172 
184  template <typename T1>
185  struct make_list1
186  : type_list<T1,nil_t>
187  { };
188 
189  template <typename T1, typename T2>
190  struct make_list2
191  : type_list<T1,type_list<T2,nil_t> >
192  { };
193 
194  template <typename T1, typename T2, typename T3>
195  struct make_list3
196  : type_list<T1, type_list<T2, type_list<T3,nil_t> > >
197  { };
198 
199  template <typename T1, typename T2, typename T3, typename T4>
200  struct make_list4
201  : type_list<T1, type_list<T2, type_list<T3, type_list<T4,nil_t> > > >
202  { };
203 
204  template <typename T1, typename T2, typename T3, typename T4, typename T5>
205  struct make_list5
206  : type_list<T1, type_list<T2, type_list<T3, type_list<T4, type_list<T5,nil_t> > > > >
207  { };
208 
209  template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
210  struct make_list6
211  : type_list<T1, type_list<T2, type_list<T3, type_list<T4, type_list<T5, type_list<T6,nil_t> > > > > >
212  { };
213 
214  /* More declarations for larger type lists may be added if necessary */
215 
216 
230  /* SR: We will not use external initialization for the static const types.
231  * Combined with template meta programming this fails in Intel compilers
232  * 11-13. Moving all the initializations inside the declarations.
233  */
234  template <typename list, typename elem>
235  struct type_list_contains {
236  static const bool value =
237  if_then_else<is_same<typename list::head, elem>::value,
238  true_type,
239  type_list_contains<typename list::tail,elem> >::type::value;
240  };
241 
242  // Base recursive case
243  template <typename elem>
244  struct type_list_contains<nil_t,elem> {
245  static const bool value = false;
246  };
247 
250  } // end namespace Meta
251 
252 } // end namespace Amesos2
253 
254 #endif // AMESOS2_META_HPP