]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/indirect_array.h
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / bits / indirect_array.h
CommitLineData
1d487aca 1// The template and inlines for the -*- C++ -*- indirect_array class.
2
fbd26352 3// Copyright (C) 1997-2019 Free Software Foundation, Inc.
1d487aca 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
1d487aca 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
6bc9506f 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/>.
1d487aca 24
5846aeac 25/** @file bits/indirect_array.h
7a472ef1 26 * This is an internal header file, included by other library headers.
5846aeac 27 * Do not attempt to use it directly. @headername{valarray}
7a472ef1 28 */
29
944beac5 30// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
31
5a64d8cf 32#ifndef _INDIRECT_ARRAY_H
33#define _INDIRECT_ARRAY_H 1
cd319190 34
35#pragma GCC system_header
1d487aca 36
2948dd21 37namespace std _GLIBCXX_VISIBILITY(default)
38{
39_GLIBCXX_BEGIN_NAMESPACE_VERSION
1069247d 40
97a32de0 41 /**
42 * @addtogroup numeric_arrays
43 * @{
44 */
45
21d4b1cc 46 /**
47 * @brief Reference to arbitrary subset of an array.
48 *
49 * An indirect_array is a reference to the actual elements of an array
95e89c24 50 * specified by an ordered array of indices. The way to get an
51 * indirect_array is to call operator[](valarray<size_t>) on a valarray.
52 * The returned indirect_array then permits carrying operations out on the
53 * referenced subset of elements in the original valarray.
21d4b1cc 54 *
55 * For example, if an indirect_array is obtained using the array (4,2,0) as
56 * an argument, and then assigned to an array containing (1,2,3), then the
57 * underlying array will have array[0]==3, array[2]==2, and array[4]==1.
58 *
59 * @param Tp Element type.
60 */
577e4091 61 template <class _Tp>
21d4b1cc 62 class indirect_array
63 {
64 public:
65 typedef _Tp value_type;
577e4091 66
aba89f4d 67 // _GLIBCXX_RESOLVE_LIB_DEFECTS
68 // 253. valarray helper functions are almost entirely useless
69
a9ca39a0 70 /// Copy constructor. Both slices refer to the same underlying array.
71 indirect_array(const indirect_array&);
72
21d4b1cc 73 /// Assignment operator. Assigns elements to corresponding elements
74 /// of @a a.
75 indirect_array& operator=(const indirect_array&);
bae9b8af 76
21d4b1cc 77 /// Assign slice elements to corresponding elements of @a v.
78 void operator=(const valarray<_Tp>&) const;
79 /// Multiply slice elements by corresponding elements of @a v.
80 void operator*=(const valarray<_Tp>&) const;
81 /// Divide slice elements by corresponding elements of @a v.
82 void operator/=(const valarray<_Tp>&) const;
83 /// Modulo slice elements by corresponding elements of @a v.
bae9b8af 84 void operator%=(const valarray<_Tp>&) const;
21d4b1cc 85 /// Add corresponding elements of @a v to slice elements.
86 void operator+=(const valarray<_Tp>&) const;
87 /// Subtract corresponding elements of @a v from slice elements.
bae9b8af 88 void operator-=(const valarray<_Tp>&) const;
21d4b1cc 89 /// Logical xor slice elements with corresponding elements of @a v.
90 void operator^=(const valarray<_Tp>&) const;
91 /// Logical and slice elements with corresponding elements of @a v.
92 void operator&=(const valarray<_Tp>&) const;
93 /// Logical or slice elements with corresponding elements of @a v.
94 void operator|=(const valarray<_Tp>&) const;
95 /// Left shift slice elements by corresponding elements of @a v.
96 void operator<<=(const valarray<_Tp>&) const;
97 /// Right shift slice elements by corresponding elements of @a v.
bae9b8af 98 void operator>>=(const valarray<_Tp>&) const;
21d4b1cc 99 /// Assign all slice elements to @a t.
100 void operator= (const _Tp&) const;
101 // ~indirect_array();
bae9b8af 102
21d4b1cc 103 template<class _Dom>
104 void operator=(const _Expr<_Dom, _Tp>&) const;
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>
bae9b8af 124 void operator>>=(const _Expr<_Dom, _Tp>&) const;
577e4091 125
21d4b1cc 126 private:
127 /// Copy constructor. Both slices refer to the same underlying array.
21d4b1cc 128 indirect_array(_Array<_Tp>, size_t, _Array<size_t>);
577e4091 129
21d4b1cc 130 friend class valarray<_Tp>;
131 friend class gslice_array<_Tp>;
bae9b8af 132
133 const size_t _M_sz;
21d4b1cc 134 const _Array<size_t> _M_index;
bae9b8af 135 const _Array<_Tp> _M_array;
136
21d4b1cc 137 // not implemented
138 indirect_array();
139 };
577e4091 140
141 template<typename _Tp>
bae9b8af 142 inline
f75d4c97 143 indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a)
aba89f4d 144 : _M_sz(__a._M_sz), _M_index(__a._M_index), _M_array(__a._M_array) {}
577e4091 145
146 template<typename _Tp>
95e89c24 147 inline
148 indirect_array<_Tp>::indirect_array(_Array<_Tp> __a, size_t __s,
149 _Array<size_t> __i)
150 : _M_sz(__s), _M_index(__i), _M_array(__a) {}
577e4091 151
152 template<typename _Tp>
95e89c24 153 inline indirect_array<_Tp>&
154 indirect_array<_Tp>::operator=(const indirect_array<_Tp>& __a)
155 {
156 std::__valarray_copy(__a._M_array, _M_sz, __a._M_index, _M_array,
157 _M_index);
158 return *this;
159 }
577e4091 160
577e4091 161 template<typename _Tp>
95e89c24 162 inline void
163 indirect_array<_Tp>::operator=(const _Tp& __t) const
164 { std::__valarray_fill(_M_array, _M_index, _M_sz, __t); }
577e4091 165
166 template<typename _Tp>
95e89c24 167 inline void
168 indirect_array<_Tp>::operator=(const valarray<_Tp>& __v) const
169 { std::__valarray_copy(_Array<_Tp>(__v), _M_sz, _M_array, _M_index); }
577e4091 170
171 template<typename _Tp>
95e89c24 172 template<class _Dom>
173 inline void
174 indirect_array<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) const
175 { std::__valarray_copy(__e, _M_sz, _M_array, _M_index); }
1d487aca 176
177#undef _DEFINE_VALARRAY_OPERATOR
f75d4c97 178#define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \
179 template<typename _Tp> \
180 inline void \
181 indirect_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const\
182 { \
183 _Array_augmented_##_Name(_M_array, _M_index, _Array<_Tp>(__v), _M_sz); \
184 } \
1d487aca 185 \
f75d4c97 186 template<typename _Tp> \
187 template<class _Dom> \
188 inline void \
189 indirect_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
190 { \
191 _Array_augmented_##_Name(_M_array, _M_index, __e, _M_sz); \
192 }
193
194_DEFINE_VALARRAY_OPERATOR(*, __multiplies)
195_DEFINE_VALARRAY_OPERATOR(/, __divides)
196_DEFINE_VALARRAY_OPERATOR(%, __modulus)
197_DEFINE_VALARRAY_OPERATOR(+, __plus)
198_DEFINE_VALARRAY_OPERATOR(-, __minus)
199_DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
200_DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
201_DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
202_DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
203_DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
1d487aca 204
205#undef _DEFINE_VALARRAY_OPERATOR
206
97a32de0 207 // @} group numeric_arrays
208
2948dd21 209_GLIBCXX_END_NAMESPACE_VERSION
210} // namespace
1d487aca 211
5a64d8cf 212#endif /* _INDIRECT_ARRAY_H */