]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/include/bits/indirect_array.h
re PR testsuite/39696 (gcc.dg/tree-ssa/ssa-ccp-25.c scan-tree-dump doesn't work on...
[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
5b9daa7e 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2009
00386a9b 4// Free Software Foundation, Inc.
725dc051
BK
5//
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)
10// any later version.
11
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.
16
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
83f51799 19// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
725dc051
BK
20// USA.
21
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.
30
729e3d3f
PE
31/** @file indirect_array.h
32 * This is an internal header file, included by other library headers.
33 * You should not attempt to use it directly.
34 */
35
143c27b0
BK
36// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
37
3d7c150e
BK
38#ifndef _INDIRECT_ARRAY_H
39#define _INDIRECT_ARRAY_H 1
b0a85b86
GDR
40
41#pragma GCC system_header
725dc051 42
3cbc7af0
BK
43_GLIBCXX_BEGIN_NAMESPACE(std)
44
5b9daa7e
BK
45 /**
46 * @addtogroup numeric_arrays
47 * @{
48 */
49
7fb397a4
JQ
50 /**
51 * @brief Reference to arbitrary subset of an array.
52 *
53 * An indirect_array is a reference to the actual elements of an array
82cb2574
PC
54 * specified by an ordered array of indices. The way to get an
55 * indirect_array is to call operator[](valarray<size_t>) on a valarray.
56 * The returned indirect_array then permits carrying operations out on the
57 * referenced subset of elements in the original valarray.
7fb397a4
JQ
58 *
59 * For example, if an indirect_array is obtained using the array (4,2,0) as
60 * an argument, and then assigned to an array containing (1,2,3), then the
61 * underlying array will have array[0]==3, array[2]==2, and array[4]==1.
62 *
63 * @param Tp Element type.
64 */
8164237c 65 template <class _Tp>
7fb397a4
JQ
66 class indirect_array
67 {
68 public:
69 typedef _Tp value_type;
8164237c 70
d4cd08dd
PC
71 // _GLIBCXX_RESOLVE_LIB_DEFECTS
72 // 253. valarray helper functions are almost entirely useless
73
ecc7568d
JQ
74 /// Copy constructor. Both slices refer to the same underlying array.
75 indirect_array(const indirect_array&);
76
7fb397a4
JQ
77 /// Assignment operator. Assigns elements to corresponding elements
78 /// of @a a.
79 indirect_array& operator=(const indirect_array&);
ed6814f7 80
7fb397a4
JQ
81 /// Assign slice elements to corresponding elements of @a v.
82 void operator=(const valarray<_Tp>&) const;
83 /// Multiply slice elements by corresponding elements of @a v.
84 void operator*=(const valarray<_Tp>&) const;
85 /// Divide slice elements by corresponding elements of @a v.
86 void operator/=(const valarray<_Tp>&) const;
87 /// Modulo slice elements by corresponding elements of @a v.
ed6814f7 88 void operator%=(const valarray<_Tp>&) const;
7fb397a4
JQ
89 /// Add corresponding elements of @a v to slice elements.
90 void operator+=(const valarray<_Tp>&) const;
91 /// Subtract corresponding elements of @a v from slice elements.
ed6814f7 92 void operator-=(const valarray<_Tp>&) const;
7fb397a4
JQ
93 /// Logical xor slice elements with corresponding elements of @a v.
94 void operator^=(const valarray<_Tp>&) const;
95 /// Logical and slice elements with corresponding elements of @a v.
96 void operator&=(const valarray<_Tp>&) const;
97 /// Logical or slice elements with corresponding elements of @a v.
98 void operator|=(const valarray<_Tp>&) const;
99 /// Left shift slice elements by corresponding elements of @a v.
100 void operator<<=(const valarray<_Tp>&) const;
101 /// Right shift slice elements by corresponding elements of @a v.
ed6814f7 102 void operator>>=(const valarray<_Tp>&) const;
7fb397a4
JQ
103 /// Assign all slice elements to @a t.
104 void operator= (const _Tp&) const;
105 // ~indirect_array();
ed6814f7 106
7fb397a4
JQ
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>
126 void operator<<=(const _Expr<_Dom, _Tp>&) const;
127 template<class _Dom>
ed6814f7 128 void operator>>=(const _Expr<_Dom, _Tp>&) const;
8164237c 129
7fb397a4
JQ
130 private:
131 /// Copy constructor. Both slices refer to the same underlying array.
7fb397a4 132 indirect_array(_Array<_Tp>, size_t, _Array<size_t>);
8164237c 133
7fb397a4
JQ
134 friend class valarray<_Tp>;
135 friend class gslice_array<_Tp>;
ed6814f7
BI
136
137 const size_t _M_sz;
7fb397a4 138 const _Array<size_t> _M_index;
ed6814f7
BI
139 const _Array<_Tp> _M_array;
140
7fb397a4
JQ
141 // not implemented
142 indirect_array();
143 };
8164237c
GDR
144
145 template<typename _Tp>
ed6814f7 146 inline
00386a9b 147 indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a)
d4cd08dd 148 : _M_sz(__a._M_sz), _M_index(__a._M_index), _M_array(__a._M_array) {}
8164237c
GDR
149
150 template<typename _Tp>
82cb2574
PC
151 inline
152 indirect_array<_Tp>::indirect_array(_Array<_Tp> __a, size_t __s,
153 _Array<size_t> __i)
154 : _M_sz(__s), _M_index(__i), _M_array(__a) {}
8164237c
GDR
155
156 template<typename _Tp>
82cb2574
PC
157 inline indirect_array<_Tp>&
158 indirect_array<_Tp>::operator=(const indirect_array<_Tp>& __a)
159 {
160 std::__valarray_copy(__a._M_array, _M_sz, __a._M_index, _M_array,
161 _M_index);
162 return *this;
163 }
8164237c 164
8164237c 165 template<typename _Tp>
82cb2574
PC
166 inline void
167 indirect_array<_Tp>::operator=(const _Tp& __t) const
168 { std::__valarray_fill(_M_array, _M_index, _M_sz, __t); }
8164237c
GDR
169
170 template<typename _Tp>
82cb2574
PC
171 inline void
172 indirect_array<_Tp>::operator=(const valarray<_Tp>& __v) const
173 { std::__valarray_copy(_Array<_Tp>(__v), _M_sz, _M_array, _M_index); }
8164237c
GDR
174
175 template<typename _Tp>
82cb2574
PC
176 template<class _Dom>
177 inline void
178 indirect_array<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) const
179 { std::__valarray_copy(__e, _M_sz, _M_array, _M_index); }
725dc051
BK
180
181#undef _DEFINE_VALARRAY_OPERATOR
00386a9b
GDR
182#define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \
183 template<typename _Tp> \
184 inline void \
185 indirect_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const\
186 { \
187 _Array_augmented_##_Name(_M_array, _M_index, _Array<_Tp>(__v), _M_sz); \
188 } \
725dc051 189 \
00386a9b
GDR
190 template<typename _Tp> \
191 template<class _Dom> \
192 inline void \
193 indirect_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
194 { \
195 _Array_augmented_##_Name(_M_array, _M_index, __e, _M_sz); \
196 }
197
198_DEFINE_VALARRAY_OPERATOR(*, __multiplies)
199_DEFINE_VALARRAY_OPERATOR(/, __divides)
200_DEFINE_VALARRAY_OPERATOR(%, __modulus)
201_DEFINE_VALARRAY_OPERATOR(+, __plus)
202_DEFINE_VALARRAY_OPERATOR(-, __minus)
203_DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
204_DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
205_DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
206_DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
207_DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
725dc051
BK
208
209#undef _DEFINE_VALARRAY_OPERATOR
210
5b9daa7e
BK
211 // @} group numeric_arrays
212
3cbc7af0 213_GLIBCXX_END_NAMESPACE
725dc051 214
3d7c150e 215#endif /* _INDIRECT_ARRAY_H */