1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | #ifndef _MASK_ARRAY_H |
33 | #define _MASK_ARRAY_H 1 |
34 | |
35 | #pragma GCC system_header |
36 | |
37 | namespace std _GLIBCXX_VISIBILITY(default) |
38 | { |
39 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | template <class _Tp> |
62 | class mask_array |
63 | { |
64 | public: |
65 | typedef _Tp value_type; |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | mask_array (const mask_array&); |
72 | |
73 | |
74 | |
75 | mask_array& operator=(const mask_array&); |
76 | |
77 | void operator=(const valarray<_Tp>&) const; |
78 | |
79 | void operator*=(const valarray<_Tp>&) const; |
80 | |
81 | void operator/=(const valarray<_Tp>&) const; |
82 | |
83 | void operator%=(const valarray<_Tp>&) const; |
84 | |
85 | void operator+=(const valarray<_Tp>&) const; |
86 | |
87 | void operator-=(const valarray<_Tp>&) const; |
88 | |
89 | void operator^=(const valarray<_Tp>&) const; |
90 | |
91 | void operator&=(const valarray<_Tp>&) const; |
92 | |
93 | void operator|=(const valarray<_Tp>&) const; |
94 | |
95 | void operator<<=(const valarray<_Tp>&) const; |
96 | |
97 | void operator>>=(const valarray<_Tp>&) const; |
98 | |
99 | void operator=(const _Tp&) const; |
100 | |
101 | |
102 | |
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> |
122 | void operator<<=(const _Expr<_Dom,_Tp>&) const; |
123 | template<class _Dom> |
124 | void operator>>=(const _Expr<_Dom,_Tp>&) const; |
125 | |
126 | private: |
127 | mask_array(_Array<_Tp>, size_t, _Array<bool>); |
128 | friend class valarray<_Tp>; |
129 | |
130 | const size_t _M_sz; |
131 | const _Array<bool> _M_mask; |
132 | const _Array<_Tp> _M_array; |
133 | |
134 | |
135 | mask_array(); |
136 | }; |
137 | |
138 | template<typename _Tp> |
139 | inline mask_array<_Tp>::mask_array(const mask_array<_Tp>& __a) |
140 | : _M_sz(__a._M_sz), _M_mask(__a._M_mask), _M_array(__a._M_array) {} |
141 | |
142 | template<typename _Tp> |
143 | inline |
144 | mask_array<_Tp>::mask_array(_Array<_Tp> __a, size_t __s, _Array<bool> __m) |
145 | : _M_sz(__s), _M_mask(__m), _M_array(__a) {} |
146 | |
147 | template<typename _Tp> |
148 | inline mask_array<_Tp>& |
149 | mask_array<_Tp>::operator=(const mask_array<_Tp>& __a) |
150 | { |
151 | std::__valarray_copy(__a._M_array, __a._M_mask, |
152 | _M_sz, _M_array, _M_mask); |
153 | return *this; |
154 | } |
155 | |
156 | template<typename _Tp> |
157 | inline void |
158 | mask_array<_Tp>::operator=(const _Tp& __t) const |
159 | { std::__valarray_fill(_M_array, _M_sz, _M_mask, __t); } |
160 | |
161 | template<typename _Tp> |
162 | inline void |
163 | mask_array<_Tp>::operator=(const valarray<_Tp>& __v) const |
164 | { std::__valarray_copy(_Array<_Tp>(__v), __v.size(), _M_array, _M_mask); } |
165 | |
166 | template<typename _Tp> |
167 | template<class _Ex> |
168 | inline void |
169 | mask_array<_Tp>::operator=(const _Expr<_Ex, _Tp>& __e) const |
170 | { std::__valarray_copy(__e, __e.size(), _M_array, _M_mask); } |
171 | |
172 | #undef _DEFINE_VALARRAY_OPERATOR |
173 | #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \ |
174 | template<typename _Tp> \ |
175 | inline void \ |
176 | mask_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \ |
177 | { \ |
178 | _Array_augmented_##_Name(_M_array, _M_mask, \ |
179 | _Array<_Tp>(__v), __v.size()); \ |
180 | } \ |
181 | \ |
182 | template<typename _Tp> \ |
183 | template<class _Dom> \ |
184 | inline void \ |
185 | mask_array<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) const\ |
186 | { \ |
187 | _Array_augmented_##_Name(_M_array, _M_mask, __e, __e.size()); \ |
188 | } |
189 | |
190 | _DEFINE_VALARRAY_OPERATOR(*, __multiplies) |
191 | _DEFINE_VALARRAY_OPERATOR(/, __divides) |
192 | _DEFINE_VALARRAY_OPERATOR(%, __modulus) |
193 | _DEFINE_VALARRAY_OPERATOR(+, __plus) |
194 | _DEFINE_VALARRAY_OPERATOR(-, __minus) |
195 | _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor) |
196 | _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and) |
197 | _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or) |
198 | _DEFINE_VALARRAY_OPERATOR(<<, __shift_left) |
199 | _DEFINE_VALARRAY_OPERATOR(>>, __shift_right) |
200 | |
201 | #undef _DEFINE_VALARRAY_OPERATOR |
202 | |
203 | |
204 | |
205 | _GLIBCXX_END_NAMESPACE_VERSION |
206 | } |
207 | |
208 | #endif |
209 | |