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