]>
Commit | Line | Data |
---|---|---|
725dc051 BK |
1 | // The template and inlines for the -*- C++ -*- mask_array class. |
2 | ||
99dee823 | 3 | // Copyright (C) 1997-2021 Free Software Foundation, Inc. |
725dc051 BK |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
725dc051 BK |
9 | // any later version. |
10 | ||
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
725dc051 | 19 | |
748086b7 JJ |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
725dc051 | 24 | |
f910786b | 25 | /** @file bits/mask_array.h |
729e3d3f | 26 | * This is an internal header file, included by other library headers. |
f910786b | 27 | * Do not attempt to use it directly. @headername{valarray} |
729e3d3f PE |
28 | */ |
29 | ||
143c27b0 BK |
30 | // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> |
31 | ||
3d7c150e BK |
32 | #ifndef _MASK_ARRAY_H |
33 | #define _MASK_ARRAY_H 1 | |
725dc051 | 34 | |
b0a85b86 GDR |
35 | #pragma GCC system_header |
36 | ||
12ffa228 BK |
37 | namespace std _GLIBCXX_VISIBILITY(default) |
38 | { | |
39 | _GLIBCXX_BEGIN_NAMESPACE_VERSION | |
3cbc7af0 | 40 | |
5b9daa7e BK |
41 | /** |
42 | * @addtogroup numeric_arrays | |
43 | * @{ | |
44 | */ | |
45 | ||
7fb397a4 JQ |
46 | /** |
47 | * @brief Reference to selected subset of an array. | |
48 | * | |
49 | * A mask_array is a reference to the actual elements of an array specified | |
50 | * by a bitmask in the form of an array of bool. The way to get a | |
51 | * mask_array is to call operator[](valarray<bool>) on a valarray. The | |
52 | * returned mask_array then permits carrying operations out on the | |
53 | * referenced subset of elements in the original valarray. | |
54 | * | |
55 | * For example, if a mask_array is obtained using the array (false, true, | |
56 | * false, true) as an argument, the mask array has two elements referring | |
57 | * to array[1] and array[3] in the underlying array. | |
58 | * | |
59 | * @param Tp Element type. | |
60 | */ | |
ed6814f7 | 61 | template <class _Tp> |
00386a9b | 62 | class mask_array |
ed6814f7 | 63 | { |
725dc051 | 64 | public: |
00386a9b | 65 | typedef _Tp value_type; |
ed6814f7 | 66 | |
d4cd08dd PC |
67 | // _GLIBCXX_RESOLVE_LIB_DEFECTS |
68 | // 253. valarray helper functions are almost entirely useless | |
69 | ||
ecc7568d JQ |
70 | /// Copy constructor. Both slices refer to the same underlying array. |
71 | mask_array (const mask_array&); | |
72 | ||
ecc7568d JQ |
73 | /// Assignment operator. Assigns elements to corresponding elements |
74 | /// of @a a. | |
75 | mask_array& operator=(const mask_array&); | |
76 | ||
00386a9b | 77 | void operator=(const valarray<_Tp>&) const; |
7fb397a4 | 78 | /// Multiply slice elements by corresponding elements of @a v. |
00386a9b | 79 | void operator*=(const valarray<_Tp>&) const; |
7fb397a4 | 80 | /// Divide slice elements by corresponding elements of @a v. |
00386a9b | 81 | void operator/=(const valarray<_Tp>&) const; |
7fb397a4 | 82 | /// Modulo slice elements by corresponding elements of @a v. |
ed6814f7 | 83 | void operator%=(const valarray<_Tp>&) const; |
7fb397a4 JQ |
84 | /// Add corresponding elements of @a v to slice elements. |
85 | void operator+=(const valarray<_Tp>&) const; | |
86 | /// Subtract corresponding elements of @a v from slice elements. | |
ed6814f7 | 87 | void operator-=(const valarray<_Tp>&) const; |
7fb397a4 JQ |
88 | /// Logical xor slice elements with corresponding elements of @a v. |
89 | void operator^=(const valarray<_Tp>&) const; | |
90 | /// Logical and slice elements with corresponding elements of @a v. | |
00386a9b | 91 | void operator&=(const valarray<_Tp>&) const; |
7fb397a4 | 92 | /// Logical or slice elements with corresponding elements of @a v. |
00386a9b | 93 | void operator|=(const valarray<_Tp>&) const; |
7fb397a4 JQ |
94 | /// Left shift slice elements by corresponding elements of @a v. |
95 | void operator<<=(const valarray<_Tp>&) const; | |
96 | /// Right shift slice elements by corresponding elements of @a v. | |
ed6814f7 | 97 | void operator>>=(const valarray<_Tp>&) const; |
7fb397a4 | 98 | /// Assign all slice elements to @a t. |
00386a9b | 99 | void operator=(const _Tp&) const; |
ed6814f7 | 100 | |
725dc051 | 101 | // ~mask_array (); |
ed6814f7 | 102 | |
00386a9b GDR |
103 | template<class _Dom> |
104 | void operator=(const _Expr<_Dom,_Tp>&) const; | |
105 | template<class _Dom> | |
106 | void operator*=(const _Expr<_Dom,_Tp>&) const; | |
107 | template<class _Dom> | |
108 | void operator/=(const _Expr<_Dom,_Tp>&) const; | |
109 | template<class _Dom> | |
110 | void operator%=(const _Expr<_Dom,_Tp>&) const; | |
111 | template<class _Dom> | |
112 | void operator+=(const _Expr<_Dom,_Tp>&) const; | |
113 | template<class _Dom> | |
114 | void operator-=(const _Expr<_Dom,_Tp>&) const; | |
115 | template<class _Dom> | |
116 | void operator^=(const _Expr<_Dom,_Tp>&) const; | |
117 | template<class _Dom> | |
118 | void operator&=(const _Expr<_Dom,_Tp>&) const; | |
119 | template<class _Dom> | |
120 | void operator|=(const _Expr<_Dom,_Tp>&) const; | |
121 | template<class _Dom> | |
725dc051 | 122 | void operator<<=(const _Expr<_Dom,_Tp>&) const; |
00386a9b | 123 | template<class _Dom> |
ed6814f7 | 124 | void operator>>=(const _Expr<_Dom,_Tp>&) const; |
725dc051 BK |
125 | |
126 | private: | |
00386a9b GDR |
127 | mask_array(_Array<_Tp>, size_t, _Array<bool>); |
128 | friend class valarray<_Tp>; | |
ed6814f7 | 129 | |
00386a9b GDR |
130 | const size_t _M_sz; |
131 | const _Array<bool> _M_mask; | |
b714a419 | 132 | const _Array<_Tp> _M_array; |
ed6814f7 | 133 | |
1b749ae9 | 134 | #if __cplusplus < 201103L |
00386a9b GDR |
135 | // not implemented |
136 | mask_array(); | |
1b749ae9 JW |
137 | #else |
138 | public: | |
139 | mask_array() = delete; | |
140 | #endif | |
725dc051 BK |
141 | }; |
142 | ||
00386a9b | 143 | template<typename _Tp> |
d34d36ef JW |
144 | inline mask_array<_Tp>::mask_array(const mask_array<_Tp>& __a) |
145 | : _M_sz(__a._M_sz), _M_mask(__a._M_mask), _M_array(__a._M_array) {} | |
725dc051 | 146 | |
00386a9b | 147 | template<typename _Tp> |
ed6814f7 | 148 | inline |
00386a9b | 149 | mask_array<_Tp>::mask_array(_Array<_Tp> __a, size_t __s, _Array<bool> __m) |
d4cd08dd | 150 | : _M_sz(__s), _M_mask(__m), _M_array(__a) {} |
ed6814f7 | 151 | |
ecc7568d JQ |
152 | template<typename _Tp> |
153 | inline mask_array<_Tp>& | |
154 | mask_array<_Tp>::operator=(const mask_array<_Tp>& __a) | |
155 | { | |
156 | std::__valarray_copy(__a._M_array, __a._M_mask, | |
157 | _M_sz, _M_array, _M_mask); | |
158 | return *this; | |
159 | } | |
160 | ||
00386a9b | 161 | template<typename _Tp> |
725dc051 | 162 | inline void |
00386a9b | 163 | mask_array<_Tp>::operator=(const _Tp& __t) const |
5b5bf717 | 164 | { std::__valarray_fill(_M_array, _M_sz, _M_mask, __t); } |
ed6814f7 | 165 | |
00386a9b | 166 | template<typename _Tp> |
725dc051 | 167 | inline void |
00386a9b | 168 | mask_array<_Tp>::operator=(const valarray<_Tp>& __v) const |
5b5bf717 | 169 | { std::__valarray_copy(_Array<_Tp>(__v), __v.size(), _M_array, _M_mask); } |
725dc051 | 170 | |
00386a9b GDR |
171 | template<typename _Tp> |
172 | template<class _Ex> | |
173 | inline void | |
174 | mask_array<_Tp>::operator=(const _Expr<_Ex, _Tp>& __e) const | |
5b5bf717 | 175 | { std::__valarray_copy(__e, __e.size(), _M_array, _M_mask); } |
725dc051 BK |
176 | |
177 | #undef _DEFINE_VALARRAY_OPERATOR | |
00386a9b GDR |
178 | #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \ |
179 | template<typename _Tp> \ | |
180 | inline void \ | |
181 | mask_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \ | |
182 | { \ | |
183 | _Array_augmented_##_Name(_M_array, _M_mask, \ | |
184 | _Array<_Tp>(__v), __v.size()); \ | |
185 | } \ | |
725dc051 | 186 | \ |
00386a9b GDR |
187 | template<typename _Tp> \ |
188 | template<class _Dom> \ | |
189 | inline void \ | |
190 | mask_array<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) const\ | |
191 | { \ | |
192 | _Array_augmented_##_Name(_M_array, _M_mask, __e, __e.size()); \ | |
193 | } | |
194 | ||
195 | _DEFINE_VALARRAY_OPERATOR(*, __multiplies) | |
196 | _DEFINE_VALARRAY_OPERATOR(/, __divides) | |
197 | _DEFINE_VALARRAY_OPERATOR(%, __modulus) | |
198 | _DEFINE_VALARRAY_OPERATOR(+, __plus) | |
199 | _DEFINE_VALARRAY_OPERATOR(-, __minus) | |
200 | _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor) | |
201 | _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and) | |
202 | _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or) | |
203 | _DEFINE_VALARRAY_OPERATOR(<<, __shift_left) | |
204 | _DEFINE_VALARRAY_OPERATOR(>>, __shift_right) | |
725dc051 | 205 | |
ed6814f7 BI |
206 | #undef _DEFINE_VALARRAY_OPERATOR |
207 | ||
f0b88346 | 208 | /// @} group numeric_arrays |
5b9daa7e | 209 | |
12ffa228 BK |
210 | _GLIBCXX_END_NAMESPACE_VERSION |
211 | } // namespace | |
725dc051 | 212 | |
3d7c150e | 213 | #endif /* _MASK_ARRAY_H */ |