1 // The template and inlines for the -*- C++ -*- gslice_array class.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2004, 2005, 2009
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 /** @file gslice_array.h
32 * This is an internal header file, included by other library headers.
33 * You should not attempt to use it directly.
36 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
38 #ifndef _GSLICE_ARRAY_H
39 #define _GSLICE_ARRAY_H 1
41 #pragma GCC system_header
43 _GLIBCXX_BEGIN_NAMESPACE(std
)
46 * @addtogroup numeric_arrays
51 * @brief Reference to multi-dimensional subset of an array.
53 * A gslice_array is a reference to the actual elements of an array
54 * specified by a gslice. The way to get a gslice_array is to call
55 * operator[](gslice) on a valarray. The returned gslice_array then
56 * permits carrying operations out on the referenced subset of elements in
57 * the original valarray. For example, operator+=(valarray) will add
58 * values to the subset of elements in the underlying valarray this
59 * gslice_array refers to.
61 * @param Tp Element type.
63 template<typename _Tp
>
67 typedef _Tp value_type
;
69 // _GLIBCXX_RESOLVE_LIB_DEFECTS
70 // 253. valarray helper functions are almost entirely useless
72 /// Copy constructor. Both slices refer to the same underlying array.
73 gslice_array(const gslice_array
&);
75 /// Assignment operator. Assigns slice elements to corresponding
77 gslice_array
& operator=(const gslice_array
&);
79 /// Assign slice elements to corresponding elements of @a v.
80 void operator=(const valarray
<_Tp
>&) const;
81 /// Multiply slice elements by corresponding elements of @a v.
82 void operator*=(const valarray
<_Tp
>&) const;
83 /// Divide slice elements by corresponding elements of @a v.
84 void operator/=(const valarray
<_Tp
>&) const;
85 /// Modulo slice elements by corresponding elements of @a v.
86 void operator%=(const valarray
<_Tp
>&) const;
87 /// Add corresponding elements of @a v to slice elements.
88 void operator+=(const valarray
<_Tp
>&) const;
89 /// Subtract corresponding elements of @a v from slice elements.
90 void operator-=(const valarray
<_Tp
>&) const;
91 /// Logical xor slice elements with corresponding elements of @a v.
92 void operator^=(const valarray
<_Tp
>&) const;
93 /// Logical and slice elements with corresponding elements of @a v.
94 void operator&=(const valarray
<_Tp
>&) const;
95 /// Logical or slice elements with corresponding elements of @a v.
96 void operator|=(const valarray
<_Tp
>&) const;
97 /// Left shift slice elements by corresponding elements of @a v.
98 void operator<<=(const valarray
<_Tp
>&) const;
99 /// Right shift slice elements by corresponding elements of @a v.
100 void operator>>=(const valarray
<_Tp
>&) const;
101 /// Assign all slice elements to @a t.
102 void operator=(const _Tp
&) const;
105 void operator=(const _Expr
<_Dom
, _Tp
>&) const;
107 void operator*=(const _Expr
<_Dom
, _Tp
>&) const;
109 void operator/=(const _Expr
<_Dom
, _Tp
>&) const;
111 void operator%=(const _Expr
<_Dom
, _Tp
>&) const;
113 void operator+=(const _Expr
<_Dom
, _Tp
>&) const;
115 void operator-=(const _Expr
<_Dom
, _Tp
>&) const;
117 void operator^=(const _Expr
<_Dom
, _Tp
>&) const;
119 void operator&=(const _Expr
<_Dom
, _Tp
>&) const;
121 void operator|=(const _Expr
<_Dom
, _Tp
>&) const;
123 void operator<<=(const _Expr
<_Dom
, _Tp
>&) const;
125 void operator>>=(const _Expr
<_Dom
, _Tp
>&) const;
128 _Array
<_Tp
> _M_array
;
129 const valarray
<size_t>& _M_index
;
131 friend class valarray
<_Tp
>;
133 gslice_array(_Array
<_Tp
>, const valarray
<size_t>&);
139 template<typename _Tp
>
141 gslice_array
<_Tp
>::gslice_array(_Array
<_Tp
> __a
,
142 const valarray
<size_t>& __i
)
143 : _M_array(__a
), _M_index(__i
) {}
145 template<typename _Tp
>
147 gslice_array
<_Tp
>::gslice_array(const gslice_array
<_Tp
>& __a
)
148 : _M_array(__a
._M_array
), _M_index(__a
._M_index
) {}
150 template<typename _Tp
>
151 inline gslice_array
<_Tp
>&
152 gslice_array
<_Tp
>::operator=(const gslice_array
<_Tp
>& __a
)
154 std::__valarray_copy(_Array
<_Tp
>(__a
._M_array
),
155 _Array
<size_t>(__a
._M_index
), _M_index
.size(),
156 _M_array
, _Array
<size_t>(_M_index
));
160 template<typename _Tp
>
162 gslice_array
<_Tp
>::operator=(const _Tp
& __t
) const
164 std::__valarray_fill(_M_array
, _Array
<size_t>(_M_index
),
165 _M_index
.size(), __t
);
168 template<typename _Tp
>
170 gslice_array
<_Tp
>::operator=(const valarray
<_Tp
>& __v
) const
172 std::__valarray_copy(_Array
<_Tp
>(__v
), __v
.size(),
173 _M_array
, _Array
<size_t>(_M_index
));
176 template<typename _Tp
>
179 gslice_array
<_Tp
>::operator=(const _Expr
<_Dom
, _Tp
>& __e
) const
181 std::__valarray_copy (__e
, _M_index
.size(), _M_array
,
182 _Array
<size_t>(_M_index
));
185 #undef _DEFINE_VALARRAY_OPERATOR
186 #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \
187 template<typename _Tp> \
189 gslice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \
191 _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index), \
192 _Array<_Tp>(__v), __v.size()); \
195 template<typename _Tp> \
196 template<class _Dom> \
198 gslice_array<_Tp>::operator _Op##= (const _Expr<_Dom, _Tp>& __e) const\
200 _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index), __e,\
204 _DEFINE_VALARRAY_OPERATOR(*, __multiplies
)
205 _DEFINE_VALARRAY_OPERATOR(/, __divides
)
206 _DEFINE_VALARRAY_OPERATOR(%, __modulus
)
207 _DEFINE_VALARRAY_OPERATOR(+, __plus
)
208 _DEFINE_VALARRAY_OPERATOR(-, __minus
)
209 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor
)
210 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and
)
211 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or
)
212 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left
)
213 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right
)
215 #undef _DEFINE_VALARRAY_OPERATOR
217 // @} group numeric_arrays
219 _GLIBCXX_END_NAMESPACE
221 #endif /* _GSLICE_ARRAY_H */