xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/include/bits/mask_array.h (revision 23f5f46327e37e7811da3520f4bb933f9489322f)
11debfc3dSmrg // The template and inlines for the -*- C++ -*- mask_array class.
21debfc3dSmrg 
38feb0f0bSmrg // Copyright (C) 1997-2020 Free Software Foundation, Inc.
41debfc3dSmrg //
51debfc3dSmrg // This file is part of the GNU ISO C++ Library.  This library is free
61debfc3dSmrg // software; you can redistribute it and/or modify it under the
71debfc3dSmrg // terms of the GNU General Public License as published by the
81debfc3dSmrg // Free Software Foundation; either version 3, or (at your option)
91debfc3dSmrg // any later version.
101debfc3dSmrg 
111debfc3dSmrg // This library is distributed in the hope that it will be useful,
121debfc3dSmrg // but WITHOUT ANY WARRANTY; without even the implied warranty of
131debfc3dSmrg // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
141debfc3dSmrg // GNU General Public License for more details.
151debfc3dSmrg 
161debfc3dSmrg // Under Section 7 of GPL version 3, you are granted additional
171debfc3dSmrg // permissions described in the GCC Runtime Library Exception, version
181debfc3dSmrg // 3.1, as published by the Free Software Foundation.
191debfc3dSmrg 
201debfc3dSmrg // You should have received a copy of the GNU General Public License and
211debfc3dSmrg // a copy of the GCC Runtime Library Exception along with this program;
221debfc3dSmrg // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
231debfc3dSmrg // <http://www.gnu.org/licenses/>.
241debfc3dSmrg 
251debfc3dSmrg /** @file bits/mask_array.h
261debfc3dSmrg  *  This is an internal header file, included by other library headers.
271debfc3dSmrg  *  Do not attempt to use it directly. @headername{valarray}
281debfc3dSmrg  */
291debfc3dSmrg 
301debfc3dSmrg // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
311debfc3dSmrg 
321debfc3dSmrg #ifndef _MASK_ARRAY_H
331debfc3dSmrg #define _MASK_ARRAY_H 1
341debfc3dSmrg 
351debfc3dSmrg #pragma GCC system_header
361debfc3dSmrg 
_GLIBCXX_VISIBILITY(default)371debfc3dSmrg namespace std _GLIBCXX_VISIBILITY(default)
381debfc3dSmrg {
391debfc3dSmrg _GLIBCXX_BEGIN_NAMESPACE_VERSION
401debfc3dSmrg 
411debfc3dSmrg   /**
421debfc3dSmrg    * @addtogroup numeric_arrays
431debfc3dSmrg    * @{
441debfc3dSmrg    */
451debfc3dSmrg 
461debfc3dSmrg   /**
471debfc3dSmrg    *  @brief  Reference to selected subset of an array.
481debfc3dSmrg    *
491debfc3dSmrg    *  A mask_array is a reference to the actual elements of an array specified
501debfc3dSmrg    *  by a bitmask in the form of an array of bool.  The way to get a
511debfc3dSmrg    *  mask_array is to call operator[](valarray<bool>) on a valarray.  The
521debfc3dSmrg    *  returned mask_array then permits carrying operations out on the
531debfc3dSmrg    *  referenced subset of elements in the original valarray.
541debfc3dSmrg    *
551debfc3dSmrg    *  For example, if a mask_array is obtained using the array (false, true,
561debfc3dSmrg    *  false, true) as an argument, the mask array has two elements referring
571debfc3dSmrg    *  to array[1] and array[3] in the underlying array.
581debfc3dSmrg    *
591debfc3dSmrg    *  @param  Tp  Element type.
601debfc3dSmrg    */
611debfc3dSmrg   template <class _Tp>
621debfc3dSmrg     class mask_array
631debfc3dSmrg     {
641debfc3dSmrg     public:
651debfc3dSmrg       typedef _Tp value_type;
661debfc3dSmrg 
671debfc3dSmrg       // _GLIBCXX_RESOLVE_LIB_DEFECTS
681debfc3dSmrg       // 253. valarray helper functions are almost entirely useless
691debfc3dSmrg 
701debfc3dSmrg       ///  Copy constructor.  Both slices refer to the same underlying array.
711debfc3dSmrg       mask_array (const mask_array&);
721debfc3dSmrg 
731debfc3dSmrg       ///  Assignment operator.  Assigns elements to corresponding elements
741debfc3dSmrg       ///  of @a a.
751debfc3dSmrg       mask_array& operator=(const mask_array&);
761debfc3dSmrg 
771debfc3dSmrg       void operator=(const valarray<_Tp>&) const;
781debfc3dSmrg       ///  Multiply slice elements by corresponding elements of @a v.
791debfc3dSmrg       void operator*=(const valarray<_Tp>&) const;
801debfc3dSmrg       ///  Divide slice elements by corresponding elements of @a v.
811debfc3dSmrg       void operator/=(const valarray<_Tp>&) const;
821debfc3dSmrg       ///  Modulo slice elements by corresponding elements of @a v.
831debfc3dSmrg       void operator%=(const valarray<_Tp>&) const;
841debfc3dSmrg       ///  Add corresponding elements of @a v to slice elements.
851debfc3dSmrg       void operator+=(const valarray<_Tp>&) const;
861debfc3dSmrg       ///  Subtract corresponding elements of @a v from slice elements.
871debfc3dSmrg       void operator-=(const valarray<_Tp>&) const;
881debfc3dSmrg       ///  Logical xor slice elements with corresponding elements of @a v.
891debfc3dSmrg       void operator^=(const valarray<_Tp>&) const;
901debfc3dSmrg       ///  Logical and slice elements with corresponding elements of @a v.
911debfc3dSmrg       void operator&=(const valarray<_Tp>&) const;
921debfc3dSmrg       ///  Logical or slice elements with corresponding elements of @a v.
931debfc3dSmrg       void operator|=(const valarray<_Tp>&) const;
941debfc3dSmrg       ///  Left shift slice elements by corresponding elements of @a v.
951debfc3dSmrg       void operator<<=(const valarray<_Tp>&) const;
961debfc3dSmrg       ///  Right shift slice elements by corresponding elements of @a v.
971debfc3dSmrg       void operator>>=(const valarray<_Tp>&) const;
981debfc3dSmrg       ///  Assign all slice elements to @a t.
991debfc3dSmrg       void operator=(const _Tp&) const;
1001debfc3dSmrg 
1011debfc3dSmrg         //        ~mask_array ();
1021debfc3dSmrg 
1031debfc3dSmrg       template<class _Dom>
1041debfc3dSmrg         void operator=(const _Expr<_Dom,_Tp>&) const;
1051debfc3dSmrg       template<class _Dom>
1061debfc3dSmrg         void operator*=(const _Expr<_Dom,_Tp>&) const;
1071debfc3dSmrg       template<class _Dom>
1081debfc3dSmrg         void operator/=(const _Expr<_Dom,_Tp>&) const;
1091debfc3dSmrg       template<class _Dom>
1101debfc3dSmrg         void operator%=(const _Expr<_Dom,_Tp>&) const;
1111debfc3dSmrg       template<class _Dom>
1121debfc3dSmrg         void operator+=(const _Expr<_Dom,_Tp>&) const;
1131debfc3dSmrg       template<class _Dom>
1141debfc3dSmrg         void operator-=(const _Expr<_Dom,_Tp>&) const;
1151debfc3dSmrg       template<class _Dom>
1161debfc3dSmrg         void operator^=(const _Expr<_Dom,_Tp>&) const;
1171debfc3dSmrg       template<class _Dom>
1181debfc3dSmrg         void operator&=(const _Expr<_Dom,_Tp>&) const;
1191debfc3dSmrg       template<class _Dom>
1201debfc3dSmrg         void operator|=(const _Expr<_Dom,_Tp>&) const;
1211debfc3dSmrg       template<class _Dom>
1221debfc3dSmrg         void operator<<=(const _Expr<_Dom,_Tp>&) const;
1231debfc3dSmrg       template<class _Dom>
1241debfc3dSmrg         void operator>>=(const _Expr<_Dom,_Tp>&) const;
1251debfc3dSmrg 
1261debfc3dSmrg     private:
1271debfc3dSmrg       mask_array(_Array<_Tp>, size_t, _Array<bool>);
1281debfc3dSmrg       friend class valarray<_Tp>;
1291debfc3dSmrg 
1301debfc3dSmrg       const size_t       _M_sz;
1311debfc3dSmrg       const _Array<bool> _M_mask;
1321debfc3dSmrg       const _Array<_Tp>  _M_array;
1331debfc3dSmrg 
134c0a68be4Smrg #if __cplusplus < 201103L
1351debfc3dSmrg       // not implemented
1361debfc3dSmrg       mask_array();
137c0a68be4Smrg #else
138c0a68be4Smrg     public:
139c0a68be4Smrg       mask_array() = delete;
140c0a68be4Smrg #endif
1411debfc3dSmrg     };
1421debfc3dSmrg 
1431debfc3dSmrg   template<typename _Tp>
1441debfc3dSmrg     inline mask_array<_Tp>::mask_array(const mask_array<_Tp>& __a)
1451debfc3dSmrg     : _M_sz(__a._M_sz), _M_mask(__a._M_mask), _M_array(__a._M_array) {}
1461debfc3dSmrg 
1471debfc3dSmrg   template<typename _Tp>
1481debfc3dSmrg     inline
1491debfc3dSmrg     mask_array<_Tp>::mask_array(_Array<_Tp> __a, size_t __s, _Array<bool> __m)
1501debfc3dSmrg     : _M_sz(__s), _M_mask(__m), _M_array(__a) {}
1511debfc3dSmrg 
1521debfc3dSmrg   template<typename _Tp>
1531debfc3dSmrg     inline mask_array<_Tp>&
1541debfc3dSmrg     mask_array<_Tp>::operator=(const mask_array<_Tp>& __a)
1551debfc3dSmrg     {
1561debfc3dSmrg       std::__valarray_copy(__a._M_array, __a._M_mask,
1571debfc3dSmrg 			   _M_sz, _M_array, _M_mask);
1581debfc3dSmrg       return *this;
1591debfc3dSmrg     }
1601debfc3dSmrg 
1611debfc3dSmrg   template<typename _Tp>
1621debfc3dSmrg     inline void
1631debfc3dSmrg     mask_array<_Tp>::operator=(const _Tp& __t) const
1641debfc3dSmrg     { std::__valarray_fill(_M_array, _M_sz, _M_mask, __t); }
1651debfc3dSmrg 
1661debfc3dSmrg   template<typename _Tp>
1671debfc3dSmrg     inline void
1681debfc3dSmrg     mask_array<_Tp>::operator=(const valarray<_Tp>& __v) const
1691debfc3dSmrg     { std::__valarray_copy(_Array<_Tp>(__v), __v.size(), _M_array, _M_mask); }
1701debfc3dSmrg 
1711debfc3dSmrg   template<typename _Tp>
1721debfc3dSmrg     template<class _Ex>
1731debfc3dSmrg       inline void
1741debfc3dSmrg       mask_array<_Tp>::operator=(const _Expr<_Ex, _Tp>& __e) const
1751debfc3dSmrg       { std::__valarray_copy(__e, __e.size(), _M_array, _M_mask); }
1761debfc3dSmrg 
177*23f5f463Smrg   /// @cond undocumented
1781debfc3dSmrg #undef _DEFINE_VALARRAY_OPERATOR
1791debfc3dSmrg #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name)				\
1801debfc3dSmrg   template<typename _Tp>						\
1811debfc3dSmrg     inline void								\
1821debfc3dSmrg     mask_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const	\
1831debfc3dSmrg     {									\
1841debfc3dSmrg       _Array_augmented_##_Name(_M_array, _M_mask,			\
1851debfc3dSmrg 			       _Array<_Tp>(__v), __v.size());		\
1861debfc3dSmrg     }									\
1871debfc3dSmrg 									\
1881debfc3dSmrg   template<typename _Tp>                                                \
1891debfc3dSmrg     template<class _Dom>			                        \
1901debfc3dSmrg       inline void							\
1911debfc3dSmrg       mask_array<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) const\
1921debfc3dSmrg       {									\
1931debfc3dSmrg 	_Array_augmented_##_Name(_M_array, _M_mask, __e, __e.size());   \
1941debfc3dSmrg       }
1951debfc3dSmrg 
1961debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
1971debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(/, __divides)
1981debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(%, __modulus)
1991debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(+, __plus)
2001debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(-, __minus)
2011debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
2021debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
2031debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
2041debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
2051debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
2061debfc3dSmrg 
2071debfc3dSmrg #undef _DEFINE_VALARRAY_OPERATOR
208*23f5f463Smrg   /// @endcond
2091debfc3dSmrg 
2108feb0f0bSmrg   /// @} group numeric_arrays
2111debfc3dSmrg 
2121debfc3dSmrg _GLIBCXX_END_NAMESPACE_VERSION
2131debfc3dSmrg } // namespace
2141debfc3dSmrg 
2151debfc3dSmrg #endif /* _MASK_ARRAY_H */
216