xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/include/bits/indirect_array.h (revision 23f5f46327e37e7811da3520f4bb933f9489322f)
11debfc3dSmrg // The template and inlines for the -*- C++ -*- indirect_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/indirect_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 _INDIRECT_ARRAY_H
331debfc3dSmrg #define _INDIRECT_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 arbitrary subset of an array.
481debfc3dSmrg    *
491debfc3dSmrg    *  An indirect_array is a reference to the actual elements of an array
501debfc3dSmrg    *  specified by an ordered array of indices.  The way to get an
511debfc3dSmrg    *  indirect_array is to call operator[](valarray<size_t>) on a valarray.
521debfc3dSmrg    *  The returned indirect_array then permits carrying operations out on the
531debfc3dSmrg    *  referenced subset of elements in the original valarray.
541debfc3dSmrg    *
551debfc3dSmrg    *  For example, if an indirect_array is obtained using the array (4,2,0) as
561debfc3dSmrg    *  an argument, and then assigned to an array containing (1,2,3), then the
571debfc3dSmrg    *  underlying array will have array[0]==3, array[2]==2, and array[4]==1.
581debfc3dSmrg    *
591debfc3dSmrg    *  @param  Tp  Element type.
601debfc3dSmrg    */
611debfc3dSmrg   template <class _Tp>
621debfc3dSmrg     class indirect_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       indirect_array(const indirect_array&);
721debfc3dSmrg 
731debfc3dSmrg       ///  Assignment operator.  Assigns elements to corresponding elements
741debfc3dSmrg       ///  of @a a.
751debfc3dSmrg       indirect_array& operator=(const indirect_array&);
761debfc3dSmrg 
771debfc3dSmrg       ///  Assign slice elements to corresponding elements of @a v.
781debfc3dSmrg       void operator=(const valarray<_Tp>&) const;
791debfc3dSmrg       ///  Multiply slice elements by corresponding elements of @a v.
801debfc3dSmrg       void operator*=(const valarray<_Tp>&) const;
811debfc3dSmrg       ///  Divide slice elements by corresponding elements of @a v.
821debfc3dSmrg       void operator/=(const valarray<_Tp>&) const;
831debfc3dSmrg       ///  Modulo slice elements by corresponding elements of @a v.
841debfc3dSmrg       void operator%=(const valarray<_Tp>&) const;
851debfc3dSmrg       ///  Add corresponding elements of @a v to slice elements.
861debfc3dSmrg       void operator+=(const valarray<_Tp>&) const;
871debfc3dSmrg       ///  Subtract corresponding elements of @a v from slice elements.
881debfc3dSmrg       void operator-=(const valarray<_Tp>&) const;
891debfc3dSmrg       ///  Logical xor slice elements with corresponding elements of @a v.
901debfc3dSmrg       void operator^=(const valarray<_Tp>&) const;
911debfc3dSmrg       ///  Logical and slice elements with corresponding elements of @a v.
921debfc3dSmrg       void operator&=(const valarray<_Tp>&) const;
931debfc3dSmrg       ///  Logical or slice elements with corresponding elements of @a v.
941debfc3dSmrg       void operator|=(const valarray<_Tp>&) const;
951debfc3dSmrg       ///  Left shift slice elements by corresponding elements of @a v.
961debfc3dSmrg       void operator<<=(const valarray<_Tp>&) const;
971debfc3dSmrg       ///  Right shift slice elements by corresponding elements of @a v.
981debfc3dSmrg       void operator>>=(const valarray<_Tp>&) const;
991debfc3dSmrg       ///  Assign all slice elements to @a t.
1001debfc3dSmrg       void operator= (const _Tp&) const;
1011debfc3dSmrg       //    ~indirect_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       ///  Copy constructor.  Both slices refer to the same underlying array.
1281debfc3dSmrg       indirect_array(_Array<_Tp>, size_t, _Array<size_t>);
1291debfc3dSmrg 
1301debfc3dSmrg       friend class valarray<_Tp>;
1311debfc3dSmrg       friend class gslice_array<_Tp>;
1321debfc3dSmrg 
1331debfc3dSmrg       const size_t	 _M_sz;
1341debfc3dSmrg       const _Array<size_t> _M_index;
1351debfc3dSmrg       const _Array<_Tp>	 _M_array;
1361debfc3dSmrg 
1371debfc3dSmrg       // not implemented
1381debfc3dSmrg       indirect_array();
1391debfc3dSmrg     };
1401debfc3dSmrg 
1411debfc3dSmrg   template<typename _Tp>
1421debfc3dSmrg     inline
1431debfc3dSmrg     indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a)
1441debfc3dSmrg     : _M_sz(__a._M_sz), _M_index(__a._M_index), _M_array(__a._M_array) {}
1451debfc3dSmrg 
1461debfc3dSmrg   template<typename _Tp>
1471debfc3dSmrg     inline
1481debfc3dSmrg     indirect_array<_Tp>::indirect_array(_Array<_Tp> __a, size_t __s,
1491debfc3dSmrg 					_Array<size_t> __i)
1501debfc3dSmrg     : _M_sz(__s), _M_index(__i), _M_array(__a) {}
1511debfc3dSmrg 
1521debfc3dSmrg   template<typename _Tp>
1531debfc3dSmrg     inline indirect_array<_Tp>&
1541debfc3dSmrg     indirect_array<_Tp>::operator=(const indirect_array<_Tp>& __a)
1551debfc3dSmrg     {
1561debfc3dSmrg       std::__valarray_copy(__a._M_array, _M_sz, __a._M_index, _M_array,
1571debfc3dSmrg 			   _M_index);
1581debfc3dSmrg       return *this;
1591debfc3dSmrg     }
1601debfc3dSmrg 
1611debfc3dSmrg   template<typename _Tp>
1621debfc3dSmrg     inline void
1631debfc3dSmrg     indirect_array<_Tp>::operator=(const _Tp& __t) const
1641debfc3dSmrg     { std::__valarray_fill(_M_array, _M_index, _M_sz, __t); }
1651debfc3dSmrg 
1661debfc3dSmrg   template<typename _Tp>
1671debfc3dSmrg     inline void
1681debfc3dSmrg     indirect_array<_Tp>::operator=(const valarray<_Tp>& __v) const
1691debfc3dSmrg     { std::__valarray_copy(_Array<_Tp>(__v), _M_sz, _M_array, _M_index); }
1701debfc3dSmrg 
1711debfc3dSmrg   template<typename _Tp>
1721debfc3dSmrg     template<class _Dom>
1731debfc3dSmrg       inline void
1741debfc3dSmrg       indirect_array<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) const
1751debfc3dSmrg       { std::__valarray_copy(__e, _M_sz, _M_array, _M_index); }
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     indirect_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const\
1831debfc3dSmrg     {									\
1841debfc3dSmrg       _Array_augmented_##_Name(_M_array, _M_index, _Array<_Tp>(__v), _M_sz); \
1851debfc3dSmrg     }									\
1861debfc3dSmrg 									\
1871debfc3dSmrg   template<typename _Tp>                                                \
1881debfc3dSmrg     template<class _Dom>				                \
1891debfc3dSmrg       inline void							\
1901debfc3dSmrg       indirect_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
1911debfc3dSmrg       {									\
1921debfc3dSmrg 	_Array_augmented_##_Name(_M_array, _M_index, __e, _M_sz);	\
1931debfc3dSmrg       }
1941debfc3dSmrg 
1951debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
1961debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(/, __divides)
1971debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(%, __modulus)
1981debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(+, __plus)
1991debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(-, __minus)
2001debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
2011debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
2021debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
2031debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
2041debfc3dSmrg _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
2051debfc3dSmrg 
2061debfc3dSmrg #undef _DEFINE_VALARRAY_OPERATOR
207*23f5f463Smrg   /// @endcond
2081debfc3dSmrg 
2098feb0f0bSmrg   /// @} group numeric_arrays
2101debfc3dSmrg 
2111debfc3dSmrg _GLIBCXX_END_NAMESPACE_VERSION
2121debfc3dSmrg } // namespace
2131debfc3dSmrg 
2141debfc3dSmrg #endif /* _INDIRECT_ARRAY_H */
215