Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_TemplateContainer.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_TEMPLATE_CONTAINER_HPP
11 #define SACADO_TEMPLATE_CONTAINER_HPP
12 
13 #include <type_traits>
14 
15 // While this code does not directly use C++11 features, it uses mpl::vector,
16 // which does
17 #include "Sacado_ConfigDefs.h"
18 
19 #include "Sacado_mpl_size.hpp"
20 #include "Sacado_mpl_find.hpp"
21 #include "Sacado_mpl_for_each.hpp"
22 #include "Sacado_mpl_apply.hpp"
23 #include "Sacado_mpl_begin.hpp"
24 #include "Sacado_mpl_end.hpp"
25 #include "Sacado_mpl_deref.hpp"
26 #include "Sacado_mpl_next.hpp"
27 #include "Sacado_mpl_enable_if.hpp"
28 
29 namespace Sacado {
30 
31  namespace Impl {
32 
33  // Forward declaration
34  template <typename TypeSeq,
35  typename ObjectT,
36  typename Iter1 = typename mpl::begin<TypeSeq>::type,
37  typename Iter2 =typename mpl::end<TypeSeq>::type>
38  struct TupleSeq;
39 
40  // Forward declaration
41  template <typename T,
42  typename TypeSeq,
43  typename ObjectT,
44  typename Iter1 = typename mpl::begin<TypeSeq>::type,
45  typename Iter2 = typename mpl::end<TypeSeq>::type,
46  typename Enabled = void>
47  struct GetTupleSeq;
48 
49  } // namespace Impl
50 
51 
53 
75  template <typename TypeSeq, typename ObjectT>
77 
80 
82  template <typename BuilderOpT>
83  struct BuildObject {
85  const BuilderOpT& builder;
87  const BuilderOpT& builder_) :
88  objects(objects_), builder(builder_) {}
89  template <typename T> void operator()(T x) const {
91  }
92  };
93 
94  public:
95 
97  typedef TypeSeq types;
98 
101 
103  template<class T>
105  return typename Sacado::mpl::apply<ObjectT,T>::type();
106  }
107 
108  };
109 
112 
115 
117  template<typename T>
120  }
121 
123  template<typename T>
124  const typename Sacado::mpl::apply<ObjectT,T>::type& get() const {
126  }
127 
129  template <typename BuilderOpT = DefaultBuilderOp>
130  void build(const BuilderOpT& builder) {
133  }
134 
135  private:
136 
139 
140  };
141 
142  // Wrap call to mpl::for_each so you don't have to specify the container
143  // or type sequence
144  template <typename TypeSeq, typename ObjectT, typename FunctorT>
146  const FunctorT& op) {
147  typedef TemplateContainer<TypeSeq,ObjectT> Container;
149  }
150 
151  // Wrap call to mpl::for_each so you don't have to specify the container
152  // or type sequence
153  template <typename TypeSeq, typename ObjectT, typename FunctorT>
155  const FunctorT& op) {
156  typedef TemplateContainer<TypeSeq,ObjectT> Container;
158  }
159 
160  namespace mpl {
161 
162  // Give TemplateContainer begin<> and end<> iterators for for_each
163 
164  template <typename TypeSeq, typename ObjectT>
165  struct begin< TemplateContainer<TypeSeq,ObjectT> > {
166  typedef typename begin<TypeSeq>::type type;
167  };
168 
169  template <typename TypeSeq, typename ObjectT>
170  struct end< TemplateContainer<TypeSeq,ObjectT> > {
171  typedef typename end<TypeSeq>::type type;
172  };
173 
174  }
175 
176  namespace Impl {
177 
178  // Container class to store our tuple sequence
179  template <typename TypeSeq,
180  typename ObjectT,
181  typename Iter1,
182  typename Iter2>
183  struct TupleSeq :
184  TupleSeq<TypeSeq, ObjectT, typename mpl::next<Iter1>::type, Iter2>
185  {
186  typedef typename mpl::apply<ObjectT,
189  };
190 
191  template <typename TypeSeq,
192  typename ObjectT,
193  typename Iter1>
194  struct TupleSeq<TypeSeq, ObjectT, Iter1, Iter1> {};
195 
196  // Helper class to get a value out of the tuple sequence from a given type
197  template <typename T,
198  typename TypeSeq,
199  typename ObjectT,
200  typename Iter1,
201  typename Iter2,
202  typename Enabled>
203  struct GetTupleSeq {};
204 
205  template <typename T,
206  typename TypeSeq,
207  typename ObjectT,
208  typename Iter1,
209  typename Iter2>
210  struct GetTupleSeq< T,
211  TypeSeq,
212  ObjectT,
213  Iter1,
214  Iter2,
215  typename mpl::enable_if_c<
216  std::is_same< T, typename mpl::deref<Iter1>::type
217  >::value
218  >::type > {
221  return t.tail;
222  }
223 
224  static const typename TupleSeq<TypeSeq,ObjectT,Iter1,Iter2>::type&
226  return t.tail;
227  }
228  };
229 
230  template <typename T,
231  typename TypeSeq,
232  typename ObjectT,
233  typename Iter1,
234  typename Iter2>
235  struct GetTupleSeq< T,
236  TypeSeq,
237  ObjectT,
238  Iter1,
239  Iter2,
240  typename mpl::enable_if_c<
241  !std::is_same< T, typename mpl::deref<Iter1>::type
242  >::value
243  >::type > :
244  GetTupleSeq< T, TypeSeq, ObjectT, typename mpl::next<Iter1>::type, Iter2>
245  {};
246 
247  template <typename T,
248  typename TypeSeq,
249  typename ObjectT,
250  typename Iter1>
251  struct GetTupleSeq< T, TypeSeq, ObjectT, Iter1, Iter1, void> {};
252 
253 
254  } // namespace Impl
255 
256 }
257 
258 #endif
Impl::TupleSeq< TypeSeq, ObjectT > tuple_type
Our container for storing each object.
void f()
Container class to manager template instantiations of a template class.
void container_for_each(TemplateContainer< TypeSeq, ObjectT > &container, const FunctorT &op)
tuple_type objects
Stores type of objects of each type.
F::template apply< A1, A2, A3, A4, A5 >::type type
The default builder class for building objects for each ScalarT.
#define T
Definition: Sacado_rad.hpp:553
void container_for_each_no_kokkos(TemplateContainer< TypeSeq, ObjectT > &container, const FunctorT &op)
static const TupleSeq< TypeSeq, ObjectT, Iter1, Iter2 >::type & apply(const TupleSeq< TypeSeq, ObjectT, Iter1, Iter2 > &t)
BuildObject(tuple_type &objects_, const BuilderOpT &builder_)
Helper class for building objects in container.
TemplateContainer()
Default constructor.
void
Definition: uninit.c:105
TypeSeq types
Type sequence containing template types.
Sacado::mpl::apply< ObjectT, T >::type operator()(T) const
Returns a new object of type ObjectT&lt;ScalarT&gt;
void build(const BuilderOpT &builder)
Build objects for each type T.
mpl::apply< ObjectT, typename mpl::deref< typename mpl::begin< TypeSeq >::type >::type >::type type