Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / libstdc++-v3 / include / bits / gslice_array.h
blob7f0325b1891ce3431d9b207f52ed00d4f74efe19
1 // The template and inlines for the -*- C++ -*- gslice_array class.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2004, 2005, 2009
4 // Free Software Foundation, Inc.
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.
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.
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
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.
31 /** @file gslice_array.h
32 * This is an internal header file, included by other library headers.
33 * You should not attempt to use it directly.
36 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
38 #ifndef _GSLICE_ARRAY_H
39 #define _GSLICE_ARRAY_H 1
41 #pragma GCC system_header
43 _GLIBCXX_BEGIN_NAMESPACE(std)
45 /**
46 * @addtogroup numeric_arrays
47 * @{
50 /**
51 * @brief Reference to multi-dimensional subset of an array.
53 * A gslice_array is a reference to the actual elements of an array
54 * specified by a gslice. The way to get a gslice_array is to call
55 * operator[](gslice) on a valarray. The returned gslice_array then
56 * permits carrying operations out on the referenced subset of elements in
57 * the original valarray. For example, operator+=(valarray) will add
58 * values to the subset of elements in the underlying valarray this
59 * gslice_array refers to.
61 * @param Tp Element type.
63 template<typename _Tp>
64 class gslice_array
66 public:
67 typedef _Tp value_type;
69 // _GLIBCXX_RESOLVE_LIB_DEFECTS
70 // 253. valarray helper functions are almost entirely useless
72 /// Copy constructor. Both slices refer to the same underlying array.
73 gslice_array(const gslice_array&);
75 /// Assignment operator. Assigns slice elements to corresponding
76 /// elements of @a a.
77 gslice_array& operator=(const gslice_array&);
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.
86 void operator%=(const valarray<_Tp>&) const;
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.
90 void operator-=(const valarray<_Tp>&) const;
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.
100 void operator>>=(const valarray<_Tp>&) const;
101 /// Assign all slice elements to @a t.
102 void operator=(const _Tp&) const;
104 template<class _Dom>
105 void operator=(const _Expr<_Dom, _Tp>&) const;
106 template<class _Dom>
107 void operator*=(const _Expr<_Dom, _Tp>&) const;
108 template<class _Dom>
109 void operator/=(const _Expr<_Dom, _Tp>&) const;
110 template<class _Dom>
111 void operator%=(const _Expr<_Dom, _Tp>&) const;
112 template<class _Dom>
113 void operator+=(const _Expr<_Dom, _Tp>&) const;
114 template<class _Dom>
115 void operator-=(const _Expr<_Dom, _Tp>&) const;
116 template<class _Dom>
117 void operator^=(const _Expr<_Dom, _Tp>&) const;
118 template<class _Dom>
119 void operator&=(const _Expr<_Dom, _Tp>&) const;
120 template<class _Dom>
121 void operator|=(const _Expr<_Dom, _Tp>&) const;
122 template<class _Dom>
123 void operator<<=(const _Expr<_Dom, _Tp>&) const;
124 template<class _Dom>
125 void operator>>=(const _Expr<_Dom, _Tp>&) const;
127 private:
128 _Array<_Tp> _M_array;
129 const valarray<size_t>& _M_index;
131 friend class valarray<_Tp>;
133 gslice_array(_Array<_Tp>, const valarray<size_t>&);
135 // not implemented
136 gslice_array();
139 template<typename _Tp>
140 inline
141 gslice_array<_Tp>::gslice_array(_Array<_Tp> __a,
142 const valarray<size_t>& __i)
143 : _M_array(__a), _M_index(__i) {}
145 template<typename _Tp>
146 inline
147 gslice_array<_Tp>::gslice_array(const gslice_array<_Tp>& __a)
148 : _M_array(__a._M_array), _M_index(__a._M_index) {}
150 template<typename _Tp>
151 inline gslice_array<_Tp>&
152 gslice_array<_Tp>::operator=(const gslice_array<_Tp>& __a)
154 std::__valarray_copy(_Array<_Tp>(__a._M_array),
155 _Array<size_t>(__a._M_index), _M_index.size(),
156 _M_array, _Array<size_t>(_M_index));
157 return *this;
160 template<typename _Tp>
161 inline void
162 gslice_array<_Tp>::operator=(const _Tp& __t) const
164 std::__valarray_fill(_M_array, _Array<size_t>(_M_index),
165 _M_index.size(), __t);
168 template<typename _Tp>
169 inline void
170 gslice_array<_Tp>::operator=(const valarray<_Tp>& __v) const
172 std::__valarray_copy(_Array<_Tp>(__v), __v.size(),
173 _M_array, _Array<size_t>(_M_index));
176 template<typename _Tp>
177 template<class _Dom>
178 inline void
179 gslice_array<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) const
181 std::__valarray_copy (__e, _M_index.size(), _M_array,
182 _Array<size_t>(_M_index));
185 #undef _DEFINE_VALARRAY_OPERATOR
186 #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \
187 template<typename _Tp> \
188 inline void \
189 gslice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \
191 _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index), \
192 _Array<_Tp>(__v), __v.size()); \
195 template<typename _Tp> \
196 template<class _Dom> \
197 inline void \
198 gslice_array<_Tp>::operator _Op##= (const _Expr<_Dom, _Tp>& __e) const\
200 _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index), __e,\
201 _M_index.size()); \
204 _DEFINE_VALARRAY_OPERATOR(*, __multiplies)
205 _DEFINE_VALARRAY_OPERATOR(/, __divides)
206 _DEFINE_VALARRAY_OPERATOR(%, __modulus)
207 _DEFINE_VALARRAY_OPERATOR(+, __plus)
208 _DEFINE_VALARRAY_OPERATOR(-, __minus)
209 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor)
210 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and)
211 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or)
212 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left)
213 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right)
215 #undef _DEFINE_VALARRAY_OPERATOR
217 // @} group numeric_arrays
219 _GLIBCXX_END_NAMESPACE
221 #endif /* _GSLICE_ARRAY_H */