DUNE-ACFEM (unstable)

foreach.hh
1#ifndef __DUNE_ACFEM_MPL_FOREACH_HH__
2#define __DUNE_ACFEM_MPL_FOREACH_HH__
3
4#include <dune/common/hybridutilities.hh>
5#include "../common/types.hh"
6#include "typetuple.hh"
7#include "access.hh"
8#include "filter.hh"
9
10namespace Dune {
11
12 namespace ACFem {
13
29 template<std::size_t... I, class F>
30 constexpr void forEach(F&& f, IndexSequence<I...> = IndexSequence<I...>{})
31 {
32 (... , std::forward<F>(f)(IndexConstant<I>{}));
33 }
34
35 template<std::size_t... I, class F>
36 constexpr void forEach(IndexSequence<I...>, F&& f)
37 {
38 (... , std::forward<F>(f)(IndexConstant<I>{}));
39 }
40
41 template<class... T, class F>
42 constexpr void forEach(MPL::TypeTuple<T...>, F&& f)
43 {
44 (... , std::forward<F>(f)(MPL::TypeWrapper<T>{}));
45 }
46
47 template<class T, class F, std::enable_if_t<IsTupleLike<T>::value, int> = 0>
48 constexpr void forEach(T&& t, F&& f)
49 {
50 forEach(MakeSequenceFor<T>{}, [&](auto i) {
51 using I = decltype(i);
52 std::forward<F>(f)(std::forward<TupleElement<I::value, T> >(get<I::value>(std::forward<T>(t))));
53 });
54 }
55
56 /***/
57 template<std::size_t N, class F>
58 constexpr void forLoop(F&& f)
59 {
60 forEach(MakeIndexSequence<N>{}, std::forward<F>(f));
61 }
62
76 template<std::size_t... I, class F>
78 {
79 return (... && (std::forward<F>(f)(IndexConstant<I>{})));
80 }
81
83 template<std::size_t... I, class F>
84 constexpr bool forEachWhile(IndexSequence<I...>, F&& f)
85 {
86 return forEachWhile<I...>(std::forward<F>(f));
87 }
88
92 template<std::size_t... I, class F, class T>
93 constexpr auto addEach(T&& init, F&& f, IndexSequence<I...> = IndexSequence<I...>{})
94 {
95 return (std::forward<T>(init) + ... + (std::forward<F>(f)(IndexConstant<I>{})));
96 }
97
101 template<std::size_t... I, class F, class T>
102 constexpr auto
103 addEach(IndexSequence<I...>, T&& init, F&& f)
104 {
105 return addEach<I...>(std::forward<F>(f), std::forward<T>(init));
106 }
107
109 template<std::size_t N, class F, class T>
110 constexpr auto addLoop(F&& f, T&& init, IndexConstant<N> = IndexConstant<N>{})
111 {
112 return addEach(MakeIndexSequence<N>{}, std::forward<F>(f), std::forward<T>(init));
113 }
114
118 template<std::size_t... I, class F, class T>
119 constexpr auto multiplyEach(T&& init, F&& f, IndexSequence<I...> = IndexSequence<I...>{})
120 {
121 return (std::forward<T>(init) * ... * (std::forward<F>(f)(IndexConstant<I>{})));
122 }
123
127 template<std::size_t... I, class F, class T>
128 constexpr auto multiplyEach(IndexSequence<I...>, T&& init, F&& f)
129 {
130 return multiplyEach<I...>(std::forward<F>(f), std::forward<T>(init));
131 }
132
134 template<std::size_t N, class F, class T>
135 constexpr auto multiplyLoop(T&& init, F&& f, IndexConstant<N> = IndexConstant<N>{})
136 {
137 return multiplyEach(MakeIndexSequence<N>{}, std::forward<F>(f), std::forward<T>(init));
138 }
139
141
143
145
146 } // ACFem::
147
148} // Dune::
149
150#endif // __DUNE_ACFEM_MPL_FOREACH_HH__
constexpr auto addEach(T &&init, F &&f, IndexSequence< I... >=IndexSequence< I... >{})
Invoke the given functor sizeof...(I) times and sum up the result, where init gives the initial value...
Definition: foreach.hh:93
constexpr bool forEachWhile(F &&f, IndexSequence< I... >=IndexSequence< I... >{})
Repeat until F returns false.
Definition: foreach.hh:77
constexpr auto addLoop(F &&f, T &&init, IndexConstant< N >=IndexConstant< N >{})
Version with just a plain number as argument.
Definition: foreach.hh:110
constexpr auto multiplyLoop(T &&init, F &&f, IndexConstant< N >=IndexConstant< N >{})
Version with just a plain number as argument.
Definition: foreach.hh:135
constexpr auto multiplyEach(T &&init, F &&f, IndexSequence< I... >=IndexSequence< I... >{})
Invoke the given functor sizeof...(I) times and multiply the result, where init gives the initial val...
Definition: foreach.hh:119
Sequence< std::size_t, V... > IndexSequence
Sequence of std::size_t values.
Definition: types.hh:64
Constant< std::size_t, V > IndexConstant
Short-cut for integral constant of type std::size_t.
Definition: types.hh:44
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Jun 19, 23:17, 2026)