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
00033
00034
00035
00036
00037
00038 #ifndef _CPP_BITS_MASK_ARRAY_H
00039 #define _CPP_BITS_MASK_ARRAY_H 1
00040
00041 #pragma GCC system_header
00042
00043 namespace std {
00044
00045 template <class _Tp>
00046 class mask_array
00047 {
00048 public:
00049 typedef _Tp value_type;
00050
00051 mask_array (const mask_array&);
00052 mask_array& operator=(const mask_array&);
00053
00054 void operator=(const valarray<_Tp>&) const;
00055 void operator*=(const valarray<_Tp>&) const;
00056 void operator/=(const valarray<_Tp>&) const;
00057 void operator%=(const valarray<_Tp>&) const;
00058 void operator+=(const valarray<_Tp>&) const;
00059 void operator-=(const valarray<_Tp>&) const;
00060 void operator^=(const valarray<_Tp>&) const;
00061 void operator&=(const valarray<_Tp>&) const;
00062 void operator|=(const valarray<_Tp>&) const;
00063 void operator<<=(const valarray<_Tp>&) const;
00064 void operator>>=(const valarray<_Tp>&) const;
00065 void operator=(const _Tp&) const;
00066
00067
00068
00069 template<class _Dom>
00070 void operator=(const _Expr<_Dom,_Tp>&) const;
00071 template<class _Dom>
00072 void operator*=(const _Expr<_Dom,_Tp>&) const;
00073 template<class _Dom>
00074 void operator/=(const _Expr<_Dom,_Tp>&) const;
00075 template<class _Dom>
00076 void operator%=(const _Expr<_Dom,_Tp>&) const;
00077 template<class _Dom>
00078 void operator+=(const _Expr<_Dom,_Tp>&) const;
00079 template<class _Dom>
00080 void operator-=(const _Expr<_Dom,_Tp>&) const;
00081 template<class _Dom>
00082 void operator^=(const _Expr<_Dom,_Tp>&) const;
00083 template<class _Dom>
00084 void operator&=(const _Expr<_Dom,_Tp>&) const;
00085 template<class _Dom>
00086 void operator|=(const _Expr<_Dom,_Tp>&) const;
00087 template<class _Dom>
00088 void operator<<=(const _Expr<_Dom,_Tp>&) const;
00089 template<class _Dom>
00090 void operator>>=(const _Expr<_Dom,_Tp>&) const;
00091
00092 private:
00093 mask_array(_Array<_Tp>, size_t, _Array<bool>);
00094 friend class valarray<_Tp>;
00095
00096 const size_t _M_sz;
00097 const _Array<bool> _M_mask;
00098 const _Array<_Tp> _M_array;
00099
00100
00101 mask_array();
00102 };
00103
00104
00105 template<typename _Tp>
00106 inline mask_array<_Tp>::mask_array(const mask_array<_Tp>& a)
00107 : _M_sz(a._M_sz), _M_mask(a._M_mask), _M_array(a._M_array) {}
00108
00109 template<typename _Tp>
00110 inline
00111 mask_array<_Tp>::mask_array(_Array<_Tp> __a, size_t __s, _Array<bool> __m)
00112 : _M_sz(__s), _M_mask(__m), _M_array(__a) {}
00113
00114 template<typename _Tp>
00115 inline mask_array<_Tp>&
00116 mask_array<_Tp>::operator=(const mask_array<_Tp>& __a)
00117 {
00118 __valarray_copy(__a._M_array, __a._M_mask,
00119 _M_sz, _M_array, _M_mask);
00120 return *this;
00121 }
00122
00123 template<typename _Tp>
00124 inline void
00125 mask_array<_Tp>::operator=(const _Tp& __t) const
00126 { __valarray_fill(_M_array, _M_sz, _M_mask, __t); }
00127
00128 template<typename _Tp>
00129 inline void
00130 mask_array<_Tp>::operator=(const valarray<_Tp>& __v) const
00131 { __valarray_copy(_Array<_Tp>(__v), __v.size(), _M_array, _M_mask); }
00132
00133 template<typename _Tp>
00134 template<class _Ex>
00135 inline void
00136 mask_array<_Tp>::operator=(const _Expr<_Ex, _Tp>& __e) const
00137 { __valarray_copy(__e, __e.size(), _M_array, _M_mask); }
00138
00139 #undef _DEFINE_VALARRAY_OPERATOR
00140 #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \
00141 template<typename _Tp> \
00142 inline void \
00143 mask_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \
00144 { \
00145 _Array_augmented_##_Name(_M_array, _M_mask, \
00146 _Array<_Tp>(__v), __v.size()); \
00147 } \
00148 \
00149 template<typename _Tp> \
00150 template<class _Dom> \
00151 inline void \
00152 mask_array<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) const\
00153 { \
00154 _Array_augmented_##_Name(_M_array, _M_mask, __e, __e.size()); \
00155 }
00156
00157 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
00158 _DEFINE_VALARRAY_OPERATOR(/, __divides)
00159 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
00160 _DEFINE_VALARRAY_OPERATOR(+, __plus)
00161 _DEFINE_VALARRAY_OPERATOR(-, __minus)
00162 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
00163 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
00164 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
00165 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
00166 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
00167
00168 #undef _DEFINE_VALARRAY_OPERATOR
00169
00170 }
00171
00172 #endif
00173
00174
00175
00176