]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/indirect_array.h
ada: Fix alignment violation for chain of aligned and misaligned composite types
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / indirect_array.h
CommitLineData
725dc051
BK
1// The template and inlines for the -*- C++ -*- indirect_array class.
2
6441eb6d 3// Copyright (C) 1997-2025 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/indirect_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 _INDIRECT_ARRAY_H
33#define _INDIRECT_ARRAY_H 1
b0a85b86 34
63a598de 35#ifdef _GLIBCXX_SYSHDR
b0a85b86 36#pragma GCC system_header
63a598de 37#endif
725dc051 38
12ffa228
BK
39namespace std _GLIBCXX_VISIBILITY(default)
40{
41_GLIBCXX_BEGIN_NAMESPACE_VERSION
3cbc7af0 42
5b9daa7e
BK
43 /**
44 * @addtogroup numeric_arrays
45 * @{
46 */
47
7fb397a4
JQ
48 /**
49 * @brief Reference to arbitrary subset of an array.
50 *
51 * An indirect_array is a reference to the actual elements of an array
82cb2574
PC
52 * specified by an ordered array of indices. The way to get an
53 * indirect_array is to call operator[](valarray<size_t>) on a valarray.
54 * The returned indirect_array then permits carrying operations out on the
55 * referenced subset of elements in the original valarray.
7fb397a4
JQ
56 *
57 * For example, if an indirect_array is obtained using the array (4,2,0) as
58 * an argument, and then assigned to an array containing (1,2,3), then the
59 * underlying array will have array[0]==3, array[2]==2, and array[4]==1.
60 *
61 * @param Tp Element type.
62 */
8164237c 63 template <class _Tp>
7fb397a4
JQ
64 class indirect_array
65 {
66 public:
67 typedef _Tp value_type;
8164237c 68
d4cd08dd
PC
69 // _GLIBCXX_RESOLVE_LIB_DEFECTS
70 // 253. valarray helper functions are almost entirely useless
71
ecc7568d
JQ
72 /// Copy constructor. Both slices refer to the same underlying array.
73 indirect_array(const indirect_array&);
74
7fb397a4
JQ
75 /// Assignment operator. Assigns elements to corresponding elements
76 /// of @a a.
77 indirect_array& operator=(const indirect_array&);
ed6814f7 78
7fb397a4
JQ
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.
ed6814f7 86 void operator%=(const valarray<_Tp>&) const;
7fb397a4
JQ
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.
ed6814f7 90 void operator-=(const valarray<_Tp>&) const;
7fb397a4
JQ
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.
ed6814f7 100 void operator>>=(const valarray<_Tp>&) const;
7fb397a4
JQ
101 /// Assign all slice elements to @a t.
102 void operator= (const _Tp&) const;
103 // ~indirect_array();
ed6814f7 104
7fb397a4
JQ
105 template<class _Dom>
106 void operator=(const _Expr<_Dom, _Tp>&) const;
107 template<class _Dom>
108 void operator*=(const _Expr<_Dom, _Tp>&) const;
109 template<class _Dom>
110 void operator/=(const _Expr<_Dom, _Tp>&) const;
111 template<class _Dom>
112 void operator%=(const _Expr<_Dom, _Tp>&) const;
113 template<class _Dom>
114 void operator+=(const _Expr<_Dom, _Tp>&) const;
115 template<class _Dom>
116 void operator-=(const _Expr<_Dom, _Tp>&) const;
117 template<class _Dom>
118 void operator^=(const _Expr<_Dom, _Tp>&) const;
119 template<class _Dom>
120 void operator&=(const _Expr<_Dom, _Tp>&) const;
121 template<class _Dom>
122 void operator|=(const _Expr<_Dom, _Tp>&) const;
123 template<class _Dom>
124 void operator<<=(const _Expr<_Dom, _Tp>&) const;
125 template<class _Dom>
ed6814f7 126 void operator>>=(const _Expr<_Dom, _Tp>&) const;
8164237c 127
7fb397a4
JQ
128 private:
129 /// Copy constructor. Both slices refer to the same underlying array.
7fb397a4 130 indirect_array(_Array<_Tp>, size_t, _Array<size_t>);
8164237c 131
7fb397a4
JQ
132 friend class valarray<_Tp>;
133 friend class gslice_array<_Tp>;
ed6814f7
BI
134
135 const size_t _M_sz;
7fb397a4 136 const _Array<size_t> _M_index;
ed6814f7
BI
137 const _Array<_Tp> _M_array;
138
7fb397a4
JQ
139 // not implemented
140 indirect_array();
141 };
8164237c
GDR
142
143 template<typename _Tp>
ed6814f7 144 inline
00386a9b 145 indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a)
d4cd08dd 146 : _M_sz(__a._M_sz), _M_index(__a._M_index), _M_array(__a._M_array) {}
8164237c
GDR
147
148 template<typename _Tp>
82cb2574
PC
149 inline
150 indirect_array<_Tp>::indirect_array(_Array<_Tp> __a, size_t __s,
151 _Array<size_t> __i)
152 : _M_sz(__s), _M_index(__i), _M_array(__a) {}
8164237c
GDR
153
154 template<typename _Tp>
82cb2574
PC
155 inline indirect_array<_Tp>&
156 indirect_array<_Tp>::operator=(const indirect_array<_Tp>& __a)
157 {
158 std::__valarray_copy(__a._M_array, _M_sz, __a._M_index, _M_array,
159 _M_index);
160 return *this;
161 }
8164237c 162
8164237c 163 template<typename _Tp>
82cb2574
PC
164 inline void
165 indirect_array<_Tp>::operator=(const _Tp& __t) const
166 { std::__valarray_fill(_M_array, _M_index, _M_sz, __t); }
8164237c
GDR
167
168 template<typename _Tp>
82cb2574
PC
169 inline void
170 indirect_array<_Tp>::operator=(const valarray<_Tp>& __v) const
171 { std::__valarray_copy(_Array<_Tp>(__v), _M_sz, _M_array, _M_index); }
8164237c
GDR
172
173 template<typename _Tp>
82cb2574
PC
174 template<class _Dom>
175 inline void
176 indirect_array<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) const
177 { std::__valarray_copy(__e, _M_sz, _M_array, _M_index); }
725dc051 178
afa69618 179 /// @cond undocumented
725dc051 180#undef _DEFINE_VALARRAY_OPERATOR
00386a9b
GDR
181#define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \
182 template<typename _Tp> \
183 inline void \
184 indirect_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const\
185 { \
186 _Array_augmented_##_Name(_M_array, _M_index, _Array<_Tp>(__v), _M_sz); \
187 } \
725dc051 188 \
00386a9b
GDR
189 template<typename _Tp> \
190 template<class _Dom> \
191 inline void \
192 indirect_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
193 { \
194 _Array_augmented_##_Name(_M_array, _M_index, __e, _M_sz); \
195 }
196
197_DEFINE_VALARRAY_OPERATOR(*, __multiplies)
198_DEFINE_VALARRAY_OPERATOR(/, __divides)
199_DEFINE_VALARRAY_OPERATOR(%, __modulus)
200_DEFINE_VALARRAY_OPERATOR(+, __plus)
201_DEFINE_VALARRAY_OPERATOR(-, __minus)
202_DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
203_DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
204_DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
205_DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
206_DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
725dc051
BK
207
208#undef _DEFINE_VALARRAY_OPERATOR
afa69618 209 /// @endcond
725dc051 210
f0b88346 211 /// @} group numeric_arrays
5b9daa7e 212
12ffa228
BK
213_GLIBCXX_END_NAMESPACE_VERSION
214} // namespace
725dc051 215
3d7c150e 216#endif /* _INDIRECT_ARRAY_H */