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