00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00038 #ifndef _MASK_ARRAY_H
00039 #define _MASK_ARRAY_H 1
00040
00041 #pragma GCC system_header
00042
00043 namespace std
00044 {
00060 template <class _Tp>
00061 class mask_array
00062 {
00063 public:
00064 typedef _Tp value_type;
00065
00066
00067
00068
00070 mask_array (const mask_array&);
00071
00074 mask_array& operator=(const mask_array&);
00075
00076 void operator=(const valarray<_Tp>&) const;
00078 void operator*=(const valarray<_Tp>&) const;
00080 void operator/=(const valarray<_Tp>&) const;
00082 void operator%=(const valarray<_Tp>&) const;
00084 void operator+=(const valarray<_Tp>&) const;
00086 void operator-=(const valarray<_Tp>&) const;
00088 void operator^=(const valarray<_Tp>&) const;
00090 void operator&=(const valarray<_Tp>&) const;
00092 void operator|=(const valarray<_Tp>&) const;
00094 void operator<<=(const valarray<_Tp>&) const;
00096 void operator>>=(const valarray<_Tp>&) const;
00098 void operator=(const _Tp&) const;
00099
00100
00101
00102 template<class _Dom>
00103 void operator=(const _Expr<_Dom,_Tp>&) const;
00104 template<class _Dom>
00105 void operator*=(const _Expr<_Dom,_Tp>&) const;
00106 template<class _Dom>
00107 void operator/=(const _Expr<_Dom,_Tp>&) const;
00108 template<class _Dom>
00109 void operator%=(const _Expr<_Dom,_Tp>&) const;
00110 template<class _Dom>
00111 void operator+=(const _Expr<_Dom,_Tp>&) const;
00112 template<class _Dom>
00113 void operator-=(const _Expr<_Dom,_Tp>&) const;
00114 template<class _Dom>
00115 void operator^=(const _Expr<_Dom,_Tp>&) const;
00116 template<class _Dom>
00117 void operator&=(const _Expr<_Dom,_Tp>&) const;
00118 template<class _Dom>
00119 void operator|=(const _Expr<_Dom,_Tp>&) const;
00120 template<class _Dom>
00121 void operator<<=(const _Expr<_Dom,_Tp>&) const;
00122 template<class _Dom>
00123 void operator>>=(const _Expr<_Dom,_Tp>&) const;
00124
00125 private:
00126 mask_array(_Array<_Tp>, size_t, _Array<bool>);
00127 friend class valarray<_Tp>;
00128
00129 const size_t _M_sz;
00130 const _Array<bool> _M_mask;
00131 const _Array<_Tp> _M_array;
00132
00133
00134 mask_array();
00135 };
00136
00137 template<typename _Tp>
00138 inline mask_array<_Tp>::mask_array(const mask_array<_Tp>& a)
00139 : _M_sz(a._M_sz), _M_mask(a._M_mask), _M_array(a._M_array) {}
00140
00141 template<typename _Tp>
00142 inline
00143 mask_array<_Tp>::mask_array(_Array<_Tp> __a, size_t __s, _Array<bool> __m)
00144 : _M_sz(__s), _M_mask(__m), _M_array(__a) {}
00145
00146 template<typename _Tp>
00147 inline mask_array<_Tp>&
00148 mask_array<_Tp>::operator=(const mask_array<_Tp>& __a)
00149 {
00150 std::__valarray_copy(__a._M_array, __a._M_mask,
00151 _M_sz, _M_array, _M_mask);
00152 return *this;
00153 }
00154
00155 template<typename _Tp>
00156 inline void
00157 mask_array<_Tp>::operator=(const _Tp& __t) const
00158 { std::__valarray_fill(_M_array, _M_sz, _M_mask, __t); }
00159
00160 template<typename _Tp>
00161 inline void
00162 mask_array<_Tp>::operator=(const valarray<_Tp>& __v) const
00163 { std::__valarray_copy(_Array<_Tp>(__v), __v.size(), _M_array, _M_mask); }
00164
00165 template<typename _Tp>
00166 template<class _Ex>
00167 inline void
00168 mask_array<_Tp>::operator=(const _Expr<_Ex, _Tp>& __e) const
00169 { std::__valarray_copy(__e, __e.size(), _M_array, _M_mask); }
00170
00171 #undef _DEFINE_VALARRAY_OPERATOR
00172 #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \
00173 template<typename _Tp> \
00174 inline void \
00175 mask_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \
00176 { \
00177 _Array_augmented_##_Name(_M_array, _M_mask, \
00178 _Array<_Tp>(__v), __v.size()); \
00179 } \
00180 \
00181 template<typename _Tp> \
00182 template<class _Dom> \
00183 inline void \
00184 mask_array<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) const\
00185 { \
00186 _Array_augmented_##_Name(_M_array, _M_mask, __e, __e.size()); \
00187 }
00188
00189 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
00190 _DEFINE_VALARRAY_OPERATOR(/, __divides)
00191 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
00192 _DEFINE_VALARRAY_OPERATOR(+, __plus)
00193 _DEFINE_VALARRAY_OPERATOR(-, __minus)
00194 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
00195 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
00196 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
00197 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
00198 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
00199
00200 #undef _DEFINE_VALARRAY_OPERATOR
00201
00202 }
00203
00204 #endif
00205
00206
00207
00208