xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/bits/gslice_array.h (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // The template and inlines for the -*- C++ -*- gslice_array class.
2*404b540aSrobert 
3*404b540aSrobert // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2004, 2005
4*404b540aSrobert // Free Software Foundation, Inc.
5*404b540aSrobert //
6*404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
7*404b540aSrobert // software; you can redistribute it and/or modify it under the
8*404b540aSrobert // terms of the GNU General Public License as published by the
9*404b540aSrobert // Free Software Foundation; either version 2, or (at your option)
10*404b540aSrobert // any later version.
11*404b540aSrobert 
12*404b540aSrobert // This library is distributed in the hope that it will be useful,
13*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of
14*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*404b540aSrobert // GNU General Public License for more details.
16*404b540aSrobert 
17*404b540aSrobert // You should have received a copy of the GNU General Public License along
18*404b540aSrobert // with this library; see the file COPYING.  If not, write to the Free
19*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20*404b540aSrobert // USA.
21*404b540aSrobert 
22*404b540aSrobert // As a special exception, you may use this file as part of a free software
23*404b540aSrobert // library without restriction.  Specifically, if other files instantiate
24*404b540aSrobert // templates or use macros or inline functions from this file, or you compile
25*404b540aSrobert // this file and link it with other files to produce an executable, this
26*404b540aSrobert // file does not by itself cause the resulting executable to be covered by
27*404b540aSrobert // the GNU General Public License.  This exception does not however
28*404b540aSrobert // invalidate any other reasons why the executable file might be covered by
29*404b540aSrobert // the GNU General Public License.
30*404b540aSrobert 
31*404b540aSrobert /** @file gslice_array.h
32*404b540aSrobert  *  This is an internal header file, included by other library headers.
33*404b540aSrobert  *  You should not attempt to use it directly.
34*404b540aSrobert  */
35*404b540aSrobert 
36*404b540aSrobert // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
37*404b540aSrobert 
38*404b540aSrobert #ifndef _GSLICE_ARRAY_H
39*404b540aSrobert #define _GSLICE_ARRAY_H 1
40*404b540aSrobert 
41*404b540aSrobert #pragma GCC system_header
42*404b540aSrobert 
_GLIBCXX_BEGIN_NAMESPACE(std)43*404b540aSrobert _GLIBCXX_BEGIN_NAMESPACE(std)
44*404b540aSrobert 
45*404b540aSrobert   /**
46*404b540aSrobert    *  @brief  Reference to multi-dimensional subset of an array.
47*404b540aSrobert    *
48*404b540aSrobert    *  A gslice_array is a reference to the actual elements of an array
49*404b540aSrobert    *  specified by a gslice.  The way to get a gslice_array is to call
50*404b540aSrobert    *  operator[](gslice) on a valarray.  The returned gslice_array then
51*404b540aSrobert    *  permits carrying operations out on the referenced subset of elements in
52*404b540aSrobert    *  the original valarray.  For example, operator+=(valarray) will add
53*404b540aSrobert    *  values to the subset of elements in the underlying valarray this
54*404b540aSrobert    *  gslice_array refers to.
55*404b540aSrobert    *
56*404b540aSrobert    *  @param  Tp  Element type.
57*404b540aSrobert    */
58*404b540aSrobert   template<typename _Tp>
59*404b540aSrobert     class gslice_array
60*404b540aSrobert     {
61*404b540aSrobert     public:
62*404b540aSrobert       typedef _Tp value_type;
63*404b540aSrobert 
64*404b540aSrobert       // _GLIBCXX_RESOLVE_LIB_DEFECTS
65*404b540aSrobert       // 253. valarray helper functions are almost entirely useless
66*404b540aSrobert 
67*404b540aSrobert       ///  Copy constructor.  Both slices refer to the same underlying array.
68*404b540aSrobert       gslice_array(const gslice_array&);
69*404b540aSrobert 
70*404b540aSrobert       ///  Assignment operator.  Assigns slice elements to corresponding
71*404b540aSrobert       ///  elements of @a a.
72*404b540aSrobert       gslice_array& operator=(const gslice_array&);
73*404b540aSrobert 
74*404b540aSrobert       ///  Assign slice elements to corresponding elements of @a v.
75*404b540aSrobert       void operator=(const valarray<_Tp>&) const;
76*404b540aSrobert       ///  Multiply slice elements by corresponding elements of @a v.
77*404b540aSrobert       void operator*=(const valarray<_Tp>&) const;
78*404b540aSrobert       ///  Divide slice elements by corresponding elements of @a v.
79*404b540aSrobert       void operator/=(const valarray<_Tp>&) const;
80*404b540aSrobert       ///  Modulo slice elements by corresponding elements of @a v.
81*404b540aSrobert       void operator%=(const valarray<_Tp>&) const;
82*404b540aSrobert       ///  Add corresponding elements of @a v to slice elements.
83*404b540aSrobert       void operator+=(const valarray<_Tp>&) const;
84*404b540aSrobert       ///  Subtract corresponding elements of @a v from slice elements.
85*404b540aSrobert       void operator-=(const valarray<_Tp>&) const;
86*404b540aSrobert       ///  Logical xor slice elements with corresponding elements of @a v.
87*404b540aSrobert       void operator^=(const valarray<_Tp>&) const;
88*404b540aSrobert       ///  Logical and slice elements with corresponding elements of @a v.
89*404b540aSrobert       void operator&=(const valarray<_Tp>&) const;
90*404b540aSrobert       ///  Logical or slice elements with corresponding elements of @a v.
91*404b540aSrobert       void operator|=(const valarray<_Tp>&) const;
92*404b540aSrobert       ///  Left shift slice elements by corresponding elements of @a v.
93*404b540aSrobert       void operator<<=(const valarray<_Tp>&) const;
94*404b540aSrobert       ///  Right shift slice elements by corresponding elements of @a v.
95*404b540aSrobert       void operator>>=(const valarray<_Tp>&) const;
96*404b540aSrobert       ///  Assign all slice elements to @a t.
97*404b540aSrobert       void operator=(const _Tp&) const;
98*404b540aSrobert 
99*404b540aSrobert       template<class _Dom>
100*404b540aSrobert         void operator=(const _Expr<_Dom, _Tp>&) const;
101*404b540aSrobert       template<class _Dom>
102*404b540aSrobert         void operator*=(const _Expr<_Dom, _Tp>&) const;
103*404b540aSrobert       template<class _Dom>
104*404b540aSrobert         void operator/=(const _Expr<_Dom, _Tp>&) const;
105*404b540aSrobert       template<class _Dom>
106*404b540aSrobert         void operator%=(const _Expr<_Dom, _Tp>&) const;
107*404b540aSrobert       template<class _Dom>
108*404b540aSrobert         void operator+=(const _Expr<_Dom, _Tp>&) const;
109*404b540aSrobert       template<class _Dom>
110*404b540aSrobert         void operator-=(const _Expr<_Dom, _Tp>&) const;
111*404b540aSrobert       template<class _Dom>
112*404b540aSrobert         void operator^=(const _Expr<_Dom, _Tp>&) const;
113*404b540aSrobert       template<class _Dom>
114*404b540aSrobert         void operator&=(const _Expr<_Dom, _Tp>&) const;
115*404b540aSrobert       template<class _Dom>
116*404b540aSrobert         void operator|=(const _Expr<_Dom, _Tp>&) const;
117*404b540aSrobert       template<class _Dom>
118*404b540aSrobert         void operator<<=(const _Expr<_Dom, _Tp>&) const;
119*404b540aSrobert       template<class _Dom>
120*404b540aSrobert         void operator>>=(const _Expr<_Dom, _Tp>&) const;
121*404b540aSrobert 
122*404b540aSrobert     private:
123*404b540aSrobert       _Array<_Tp>    _M_array;
124*404b540aSrobert       const valarray<size_t>& _M_index;
125*404b540aSrobert 
126*404b540aSrobert       friend class valarray<_Tp>;
127*404b540aSrobert 
128*404b540aSrobert       gslice_array(_Array<_Tp>, const valarray<size_t>&);
129*404b540aSrobert 
130*404b540aSrobert       // not implemented
131*404b540aSrobert       gslice_array();
132*404b540aSrobert     };
133*404b540aSrobert 
134*404b540aSrobert   template<typename _Tp>
135*404b540aSrobert     inline
gslice_array(_Array<_Tp> __a,const valarray<size_t> & __i)136*404b540aSrobert     gslice_array<_Tp>::gslice_array(_Array<_Tp> __a,
137*404b540aSrobert 				    const valarray<size_t>& __i)
138*404b540aSrobert     : _M_array(__a), _M_index(__i) {}
139*404b540aSrobert 
140*404b540aSrobert   template<typename _Tp>
141*404b540aSrobert     inline
gslice_array(const gslice_array<_Tp> & __a)142*404b540aSrobert     gslice_array<_Tp>::gslice_array(const gslice_array<_Tp>& __a)
143*404b540aSrobert     : _M_array(__a._M_array), _M_index(__a._M_index) {}
144*404b540aSrobert 
145*404b540aSrobert   template<typename _Tp>
146*404b540aSrobert     inline gslice_array<_Tp>&
147*404b540aSrobert     gslice_array<_Tp>::operator=(const gslice_array<_Tp>& __a)
148*404b540aSrobert     {
149*404b540aSrobert       std::__valarray_copy(_Array<_Tp>(__a._M_array),
150*404b540aSrobert 			   _Array<size_t>(__a._M_index), _M_index.size(),
151*404b540aSrobert 			   _M_array, _Array<size_t>(_M_index));
152*404b540aSrobert       return *this;
153*404b540aSrobert     }
154*404b540aSrobert 
155*404b540aSrobert   template<typename _Tp>
156*404b540aSrobert     inline void
157*404b540aSrobert     gslice_array<_Tp>::operator=(const _Tp& __t) const
158*404b540aSrobert     {
159*404b540aSrobert       std::__valarray_fill(_M_array, _Array<size_t>(_M_index),
160*404b540aSrobert 			   _M_index.size(), __t);
161*404b540aSrobert     }
162*404b540aSrobert 
163*404b540aSrobert   template<typename _Tp>
164*404b540aSrobert     inline void
165*404b540aSrobert     gslice_array<_Tp>::operator=(const valarray<_Tp>& __v) const
166*404b540aSrobert     {
167*404b540aSrobert       std::__valarray_copy(_Array<_Tp>(__v), __v.size(),
168*404b540aSrobert 			   _M_array, _Array<size_t>(_M_index));
169*404b540aSrobert     }
170*404b540aSrobert 
171*404b540aSrobert   template<typename _Tp>
172*404b540aSrobert     template<class _Dom>
173*404b540aSrobert       inline void
174*404b540aSrobert       gslice_array<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) const
175*404b540aSrobert       {
176*404b540aSrobert 	std::__valarray_copy (__e, _M_index.size(), _M_array,
177*404b540aSrobert 			      _Array<size_t>(_M_index));
178*404b540aSrobert       }
179*404b540aSrobert 
180*404b540aSrobert #undef _DEFINE_VALARRAY_OPERATOR
181*404b540aSrobert #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name)				\
182*404b540aSrobert   template<typename _Tp>						\
183*404b540aSrobert     inline void								\
184*404b540aSrobert     gslice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const	\
185*404b540aSrobert     {									\
186*404b540aSrobert       _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index),	\
187*404b540aSrobert 			       _Array<_Tp>(__v), __v.size());		\
188*404b540aSrobert     }									\
189*404b540aSrobert 									\
190*404b540aSrobert   template<typename _Tp>                                                \
191*404b540aSrobert     template<class _Dom>				                \
192*404b540aSrobert       inline void							\
193*404b540aSrobert       gslice_array<_Tp>::operator _Op##= (const _Expr<_Dom, _Tp>& __e) const\
194*404b540aSrobert       {									\
195*404b540aSrobert 	_Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index), __e,\
196*404b540aSrobert 				 _M_index.size());			\
197*404b540aSrobert       }
198*404b540aSrobert 
199*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
200*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(/, __divides)
201*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(%, __modulus)
202*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(+, __plus)
203*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(-, __minus)
204*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
205*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
206*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
207*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
208*404b540aSrobert _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
209*404b540aSrobert 
210*404b540aSrobert #undef _DEFINE_VALARRAY_OPERATOR
211*404b540aSrobert 
212*404b540aSrobert _GLIBCXX_END_NAMESPACE
213*404b540aSrobert 
214*404b540aSrobert #endif /* _GSLICE_ARRAY_H */
215