]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/include/bits/indirect_array.h
Remove trailing whitespace (see ChangeLog for longwinded description).
[gcc.git] / libstdc++-v3 / include / bits / indirect_array.h
CommitLineData
725dc051
BK
1// The template and inlines for the -*- C++ -*- indirect_array class.
2
06a81b60 3// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004
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
19// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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
31// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
32
729e3d3f
PE
33/** @file indirect_array.h
34 * This is an internal header file, included by other library headers.
35 * You should not attempt to use it directly.
36 */
37
3d7c150e
BK
38#ifndef _INDIRECT_ARRAY_H
39#define _INDIRECT_ARRAY_H 1
b0a85b86
GDR
40
41#pragma GCC system_header
725dc051 42
8164237c
GDR
43namespace std
44{
7fb397a4
JQ
45 /**
46 * @brief Reference to arbitrary subset of an array.
47 *
48 * An indirect_array is a reference to the actual elements of an array
49 * specified by an ordered array of indices. The way to get an indirect_array is to
50 * call operator[](valarray<size_t>) on a valarray. The returned
51 * indirect_array then permits carrying operations out on the referenced
52 * subset of elements in the original valarray.
53 *
54 * For example, if an indirect_array is obtained using the array (4,2,0) as
55 * an argument, and then assigned to an array containing (1,2,3), then the
56 * underlying array will have array[0]==3, array[2]==2, and array[4]==1.
57 *
58 * @param Tp Element type.
59 */
8164237c 60 template <class _Tp>
7fb397a4
JQ
61 class indirect_array
62 {
63 public:
64 typedef _Tp value_type;
8164237c 65
7fb397a4
JQ
66 // XXX: This is a proposed resolution for DR-253.
67 /// Assignment operator. Assigns elements to corresponding elements
68 /// of @a a.
69 indirect_array& operator=(const indirect_array&);
ed6814f7 70
7fb397a4
JQ
71 /// Assign slice elements to corresponding elements of @a v.
72 void operator=(const valarray<_Tp>&) const;
73 /// Multiply slice elements by corresponding elements of @a v.
74 void operator*=(const valarray<_Tp>&) const;
75 /// Divide slice elements by corresponding elements of @a v.
76 void operator/=(const valarray<_Tp>&) const;
77 /// Modulo slice elements by corresponding elements of @a v.
ed6814f7 78 void operator%=(const valarray<_Tp>&) const;
7fb397a4
JQ
79 /// Add corresponding elements of @a v to slice elements.
80 void operator+=(const valarray<_Tp>&) const;
81 /// Subtract corresponding elements of @a v from slice elements.
ed6814f7 82 void operator-=(const valarray<_Tp>&) const;
7fb397a4
JQ
83 /// Logical xor slice elements with corresponding elements of @a v.
84 void operator^=(const valarray<_Tp>&) const;
85 /// Logical and slice elements with corresponding elements of @a v.
86 void operator&=(const valarray<_Tp>&) const;
87 /// Logical or slice elements with corresponding elements of @a v.
88 void operator|=(const valarray<_Tp>&) const;
89 /// Left shift slice elements by corresponding elements of @a v.
90 void operator<<=(const valarray<_Tp>&) const;
91 /// Right shift slice elements by corresponding elements of @a v.
ed6814f7 92 void operator>>=(const valarray<_Tp>&) const;
7fb397a4
JQ
93 /// Assign all slice elements to @a t.
94 void operator= (const _Tp&) const;
95 // ~indirect_array();
ed6814f7 96
7fb397a4
JQ
97 template<class _Dom>
98 void operator=(const _Expr<_Dom, _Tp>&) const;
99 template<class _Dom>
100 void operator*=(const _Expr<_Dom, _Tp>&) const;
101 template<class _Dom>
102 void operator/=(const _Expr<_Dom, _Tp>&) const;
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>
ed6814f7 118 void operator>>=(const _Expr<_Dom, _Tp>&) const;
8164237c 119
7fb397a4
JQ
120 private:
121 /// Copy constructor. Both slices refer to the same underlying array.
122 indirect_array(const indirect_array&);
123 indirect_array(_Array<_Tp>, size_t, _Array<size_t>);
8164237c 124
7fb397a4
JQ
125 friend class valarray<_Tp>;
126 friend class gslice_array<_Tp>;
ed6814f7
BI
127
128 const size_t _M_sz;
7fb397a4 129 const _Array<size_t> _M_index;
ed6814f7
BI
130 const _Array<_Tp> _M_array;
131
7fb397a4
JQ
132 // not implemented
133 indirect_array();
134 };
8164237c
GDR
135
136 template<typename _Tp>
ed6814f7 137 inline
00386a9b
GDR
138 indirect_array<_Tp>::indirect_array(const indirect_array<_Tp>& __a)
139 : _M_sz(__a._M_sz), _M_index(__a._M_index), _M_array(__a._M_array) {}
8164237c
GDR
140
141 template<typename _Tp>
142 inline
ed6814f7 143 indirect_array<_Tp>::indirect_array(_Array<_Tp> __a, size_t __s,
00386a9b
GDR
144 _Array<size_t> __i)
145 : _M_sz(__s), _M_index(__i), _M_array(__a) {}
8164237c
GDR
146
147 template<typename _Tp>
148 inline indirect_array<_Tp>&
149 indirect_array<_Tp>::operator=(const indirect_array<_Tp>& __a)
150 {
5b5bf717 151 std::__valarray_copy(__a._M_array, _M_sz, __a._M_index, _M_array, _M_index);
8164237c
GDR
152 return *this;
153 }
154
155
156 template<typename _Tp>
157 inline void
00386a9b 158 indirect_array<_Tp>::operator=(const _Tp& __t) const
5b5bf717 159 { std::__valarray_fill(_M_array, _M_index, _M_sz, __t); }
8164237c
GDR
160
161 template<typename _Tp>
162 inline void
00386a9b 163 indirect_array<_Tp>::operator=(const valarray<_Tp>& __v) const
5b5bf717 164 { std::__valarray_copy(_Array<_Tp>(__v), _M_sz, _M_array, _M_index); }
8164237c
GDR
165
166 template<typename _Tp>
167 template<class _Dom>
00386a9b
GDR
168 inline void
169 indirect_array<_Tp>::operator=(const _Expr<_Dom,_Tp>& __e) const
5b5bf717 170 { std::__valarray_copy(__e, _M_sz, _M_array, _M_index); }
725dc051
BK
171
172#undef _DEFINE_VALARRAY_OPERATOR
00386a9b
GDR
173#define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \
174 template<typename _Tp> \
175 inline void \
176 indirect_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const\
177 { \
178 _Array_augmented_##_Name(_M_array, _M_index, _Array<_Tp>(__v), _M_sz); \
179 } \
725dc051 180 \
00386a9b
GDR
181 template<typename _Tp> \
182 template<class _Dom> \
183 inline void \
184 indirect_array<_Tp>::operator _Op##=(const _Expr<_Dom,_Tp>& __e) const\
185 { \
186 _Array_augmented_##_Name(_M_array, _M_index, __e, _M_sz); \
187 }
188
189_DEFINE_VALARRAY_OPERATOR(*, __multiplies)
190_DEFINE_VALARRAY_OPERATOR(/, __divides)
191_DEFINE_VALARRAY_OPERATOR(%, __modulus)
192_DEFINE_VALARRAY_OPERATOR(+, __plus)
193_DEFINE_VALARRAY_OPERATOR(-, __minus)
194_DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
195_DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
196_DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
197_DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
198_DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
725dc051
BK
199
200#undef _DEFINE_VALARRAY_OPERATOR
201
202} // std::
203
3d7c150e 204#endif /* _INDIRECT_ARRAY_H */
725dc051
BK
205
206// Local Variables:
207// mode:c++
208// End:
This page took 0.345733 seconds and 5 git commands to generate.