DUNE-ACFEM (unstable)

mask.hh
1#ifndef __DUNE_ACFEM_MPL_MASK_HH__
2#define __DUNE_ACFEM_MPL_MASK_HH__
3
4#include "access.hh"
5
6namespace Dune {
7
8 namespace ACFem {
9
30 namespace {
31 // helper templates in order to convert a bit-mask in into the
32 // sequence of set-bit positions.
33
34 template<std::size_t mask, std::size_t N, class = void, std::size_t... I>
35 struct MaskSequenceHelper;
36
37 template<std::size_t mask, std::size_t N, std::size_t... I>
38 struct MaskSequenceHelper<mask, N, std::enable_if_t<mask & 1>, I...>
39 {
40 typedef typename MaskSequenceHelper<(mask/2), N+1, void, I..., N>::type type;
41 };
42
43 template<std::size_t mask, std::size_t N, std::size_t... I>
44 struct MaskSequenceHelper<mask, N, std::enable_if_t<mask != 0 && !(mask & 1)>, I...>
45 {
46 typedef typename MaskSequenceHelper<(mask/2), N+1, void, I...>::type type;
47 };
48
49 // recursion end-point
50 template<std::size_t mask, std::size_t N, std::size_t... I>
51 struct MaskSequenceHelper<mask, N, std::enable_if_t<mask == 0>, I...>
52 {
53 typedef std::index_sequence<I...> type;
54 };
55
56 template<std::size_t... I>
57 struct SequenceMaskHelper;
58
59 template<std::size_t I0, std::size_t... I>
60 struct SequenceMaskHelper<I0, I...>
61 {
62 static constexpr std::size_t value = (1UL << I0)|SequenceMaskHelper<I...>::value;
63 };
64
65 template<>
66 struct SequenceMaskHelper<>
67 {
68 static constexpr std::size_t value = 0UL;
69 };
70 }
71
73 template<std::size_t mask>
74 using MaskSequence = typename MaskSequenceHelper<mask, 0>::type;
75
77 template<std::size_t... I>
78 using SequenceMask = IndexConstant<SequenceMaskHelper<I...>::value>;
79
81 template<std::size_t... I>
82 constexpr auto sequenceMask(const IndexSequence<I...>&)
83 {
84 return SequenceMask<I...>::value;
85 }
86
88 template<std::size_t Mask, std::size_t Bit>
90
92 constexpr bool hasBit(const std::size_t& mask, const std::size_t& bit)
93 {
94 return mask & (1 << bit);
95 }
96
97 namespace {
98 template<class Sup, class Sub, class = void>
99 struct CondenseMaskHelper;
100
101 template<class T, T Sup, T Sub>
102 struct CondenseMaskHelper<Constant<T, Sup>, Constant<T, Sub>, std::enable_if_t<Sup & 1> >
103 {
104 static constexpr T value = (Sub & 1) | CondenseMaskHelper<Constant<T, (Sup >> 1)>, Constant<T, (Sub >> 1)> >::value << 1;
105 };
106
107 template<class T, T Sup, T Sub>
108 struct CondenseMaskHelper<Constant<T, Sup>, Constant<T, Sub>, std::enable_if_t<(Sup > 0) && !(Sup & 1)> >
109 {
110 static_assert(!(Sub & 1), "Sub-mask not sub-ordinate to super-mask");
111 static constexpr T value = CondenseMaskHelper<Constant<T, (Sup >> 1)>, Constant<T, (Sub >> 1)> >::value;
112 };
113
114 template<class T, T Sub>
115 struct CondenseMaskHelper<Constant<T, 0>, Constant<T, Sub> >
116 {
117 static_assert(Sub == 0, "Sub-mask not sub-ordinate to super-mask");
118 static constexpr T value = (T)0;
119 };
120 }
121
130 template<std::size_t Super, std::size_t Sub>
132
134
136
138
139 } // ACFem::
140
141} // Dune::
142
143#endif // __DUNE_ACFEM_MPL_MASK_HH__
constexpr bool hasBit(const std::size_t &mask, const std::size_t &bit)
std::true_type if Mask has Bit set.
Definition: mask.hh:92
typename MaskSequenceHelper< mask, 0 >::type MaskSequence
Generate the index-sequence type of set bits from a bit-mask.
Definition: mask.hh:74
BoolConstant<(Mask &SequenceMask< Bit >::value) !=0UL > HasBit
std::true_type if Mask has Bit set.
Definition: mask.hh:89
constexpr auto sequenceMask(const IndexSequence< I... > &)
Generate a bit-mask from the given index-sequence.
Definition: mask.hh:82
IndexConstant< CondenseMaskHelper< IndexConstant< Super >, IndexConstant< Sub > >::value > CondensedMask
Transform the bit-mask given in Sub be removing all bit-positions of zeros in Super.
Definition: mask.hh:131
IndexConstant< SequenceMaskHelper< I... >::value > SequenceMask
Generate a bit-mask from the given index-sequence.
Definition: mask.hh:78
Sequence< std::size_t, V... > IndexSequence
Sequence of std::size_t values.
Definition: types.hh:64
integral_constant< T, V > Constant
Short-cut for any integral constant.
Definition: types.hh:40
Constant< bool, V > BoolConstant
Short-cut for integral constant of type bool.
Definition: types.hh:48
Constant< std::size_t, V > IndexConstant
Short-cut for integral constant of type std::size_t.
Definition: types.hh:44
STL namespace.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Jun 19, 23:17, 2026)