Chris@16
|
1 //
|
Chris@16
|
2 // Copyright (c) 2000-2010
|
Chris@16
|
3 // Joerg Walter, Mathias Koch, David Bellot
|
Chris@101
|
4 // Copyright (c) 2014, Athanasios Iliopoulos
|
Chris@16
|
5 //
|
Chris@16
|
6 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
7 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
8 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
9 //
|
Chris@16
|
10 // The authors gratefully acknowledge the support of
|
Chris@16
|
11 // GeNeSys mbH & Co. KG in producing this work.
|
Chris@16
|
12 //
|
Chris@16
|
13 // And we acknowledge the support from all contributors.
|
Chris@16
|
14
|
Chris@16
|
15 /// \file vector.hpp Definition for the class vector and its derivative
|
Chris@16
|
16
|
Chris@16
|
17 #ifndef _BOOST_UBLAS_VECTOR_
|
Chris@16
|
18 #define _BOOST_UBLAS_VECTOR_
|
Chris@16
|
19
|
Chris@101
|
20 #include <boost/config.hpp>
|
Chris@16
|
21 #include <boost/numeric/ublas/storage.hpp>
|
Chris@16
|
22 #include <boost/numeric/ublas/vector_expression.hpp>
|
Chris@16
|
23 #include <boost/numeric/ublas/detail/vector_assign.hpp>
|
Chris@16
|
24 #include <boost/serialization/collection_size_type.hpp>
|
Chris@16
|
25 #include <boost/serialization/nvp.hpp>
|
Chris@16
|
26
|
Chris@101
|
27 #ifdef BOOST_UBLAS_CPP_GE_2011
|
Chris@101
|
28 #include <array>
|
Chris@101
|
29 #include <initializer_list>
|
Chris@101
|
30 #if defined(BOOST_MSVC) // For std::forward in fixed_vector
|
Chris@101
|
31 #include <utility>
|
Chris@101
|
32 #endif
|
Chris@101
|
33 #endif
|
Chris@16
|
34
|
Chris@16
|
35 // Iterators based on ideas of Jeremy Siek
|
Chris@16
|
36
|
Chris@16
|
37 namespace boost { namespace numeric { namespace ublas {
|
Chris@16
|
38
|
Chris@16
|
39 /** \brief A dense vector of values of type \c T.
|
Chris@16
|
40 *
|
Chris@16
|
41 * For a \f$n\f$-dimensional vector \f$v\f$ and \f$0\leq i < n\f$ every element \f$v_i\f$ is mapped
|
Chris@16
|
42 * to the \f$i\f$-th element of the container. A storage type \c A can be specified which defaults to \c unbounded_array.
|
Chris@16
|
43 * Elements are constructed by \c A, which need not initialise their value.
|
Chris@16
|
44 *
|
Chris@16
|
45 * \tparam T type of the objects stored in the vector (like int, double, complex,...)
|
Chris@16
|
46 * \tparam A The type of the storage array of the vector. Default is \c unbounded_array<T>. \c <bounded_array<T> and \c std::vector<T> can also be used
|
Chris@16
|
47 */
|
Chris@16
|
48 template<class T, class A>
|
Chris@16
|
49 class vector:
|
Chris@16
|
50 public vector_container<vector<T, A> > {
|
Chris@16
|
51
|
Chris@16
|
52 typedef vector<T, A> self_type;
|
Chris@16
|
53 public:
|
Chris@16
|
54 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
|
Chris@16
|
55 using vector_container<self_type>::operator ();
|
Chris@16
|
56 #endif
|
Chris@16
|
57
|
Chris@16
|
58 typedef typename A::size_type size_type;
|
Chris@16
|
59 typedef typename A::difference_type difference_type;
|
Chris@16
|
60 typedef T value_type;
|
Chris@16
|
61 typedef typename type_traits<T>::const_reference const_reference;
|
Chris@16
|
62 typedef T &reference;
|
Chris@16
|
63 typedef T *pointer;
|
Chris@16
|
64 typedef const T *const_pointer;
|
Chris@16
|
65 typedef A array_type;
|
Chris@16
|
66 typedef const vector_reference<const self_type> const_closure_type;
|
Chris@16
|
67 typedef vector_reference<self_type> closure_type;
|
Chris@16
|
68 typedef self_type vector_temporary_type;
|
Chris@16
|
69 typedef dense_tag storage_category;
|
Chris@16
|
70
|
Chris@16
|
71 // Construction and destruction
|
Chris@16
|
72
|
Chris@16
|
73 /// \brief Constructor of a vector
|
Chris@16
|
74 /// By default it is empty, i.e. \c size()==0.
|
Chris@16
|
75 BOOST_UBLAS_INLINE
|
Chris@16
|
76 vector ():
|
Chris@16
|
77 vector_container<self_type> (),
|
Chris@16
|
78 data_ () {}
|
Chris@16
|
79
|
Chris@16
|
80 /// \brief Constructor of a vector with a predefined size
|
Chris@16
|
81 /// By default, its elements are initialized to 0.
|
Chris@16
|
82 /// \param size initial size of the vector
|
Chris@16
|
83 explicit BOOST_UBLAS_INLINE
|
Chris@16
|
84 vector (size_type size):
|
Chris@16
|
85 vector_container<self_type> (),
|
Chris@16
|
86 data_ (size) {
|
Chris@16
|
87 }
|
Chris@16
|
88
|
Chris@16
|
89 /// \brief Constructor of a vector by copying from another container
|
Chris@16
|
90 /// This type has the generic name \c array_typ within the vector definition.
|
Chris@16
|
91 /// \param size initial size of the vector \bug this value is not used
|
Chris@16
|
92 /// \param data container of type \c A
|
Chris@16
|
93 /// \todo remove this definition because \c size is not used
|
Chris@16
|
94 BOOST_UBLAS_INLINE
|
Chris@101
|
95 vector (size_type /*size*/, const array_type &data):
|
Chris@16
|
96 vector_container<self_type> (),
|
Chris@16
|
97 data_ (data) {}
|
Chris@16
|
98
|
Chris@16
|
99 /// \brief Constructor of a vector by copying from another container
|
Chris@16
|
100 /// This type has the generic name \c array_typ within the vector definition.
|
Chris@16
|
101 /// \param data container of type \c A
|
Chris@16
|
102 BOOST_UBLAS_INLINE
|
Chris@16
|
103 vector (const array_type &data):
|
Chris@16
|
104 vector_container<self_type> (),
|
Chris@16
|
105 data_ (data) {}
|
Chris@16
|
106
|
Chris@16
|
107 /// \brief Constructor of a vector with a predefined size and a unique initial value
|
Chris@16
|
108 /// \param size of the vector
|
Chris@16
|
109 /// \param init value to assign to each element of the vector
|
Chris@16
|
110 BOOST_UBLAS_INLINE
|
Chris@16
|
111 vector (size_type size, const value_type &init):
|
Chris@16
|
112 vector_container<self_type> (),
|
Chris@16
|
113 data_ (size, init) {}
|
Chris@16
|
114
|
Chris@16
|
115 /// \brief Copy-constructor of a vector
|
Chris@16
|
116 /// \param v is the vector to be duplicated
|
Chris@16
|
117 BOOST_UBLAS_INLINE
|
Chris@16
|
118 vector (const vector &v):
|
Chris@16
|
119 vector_container<self_type> (),
|
Chris@16
|
120 data_ (v.data_) {}
|
Chris@16
|
121
|
Chris@16
|
122 /// \brief Copy-constructor of a vector from a vector_expression
|
Chris@16
|
123 /// Depending on the vector_expression, this constructor can have the cost of the computations
|
Chris@16
|
124 /// of the expression (trivial to say it, but it is to take into account in your complexity calculations).
|
Chris@16
|
125 /// \param ae the vector_expression which values will be duplicated into the vector
|
Chris@16
|
126 template<class AE>
|
Chris@16
|
127 BOOST_UBLAS_INLINE
|
Chris@16
|
128 vector (const vector_expression<AE> &ae):
|
Chris@16
|
129 vector_container<self_type> (),
|
Chris@16
|
130 data_ (ae ().size ()) {
|
Chris@16
|
131 vector_assign<scalar_assign> (*this, ae);
|
Chris@16
|
132 }
|
Chris@16
|
133
|
Chris@16
|
134 // -----------------------
|
Chris@16
|
135 // Random Access Container
|
Chris@16
|
136 // -----------------------
|
Chris@16
|
137
|
Chris@16
|
138 /// \brief Return the maximum size of the data container.
|
Chris@16
|
139 /// Return the upper bound (maximum size) on the data container. Depending on the container, it can be bigger than the current size of the vector.
|
Chris@16
|
140 BOOST_UBLAS_INLINE
|
Chris@16
|
141 size_type max_size () const {
|
Chris@16
|
142 return data_.max_size ();
|
Chris@16
|
143 }
|
Chris@16
|
144
|
Chris@16
|
145 /// \brief Return true if the vector is empty (\c size==0)
|
Chris@16
|
146 /// \return \c true if empty, \c false otherwise
|
Chris@16
|
147 BOOST_UBLAS_INLINE
|
Chris@16
|
148 bool empty () const {
|
Chris@16
|
149 return data_.size () == 0;
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 // ---------
|
Chris@16
|
153 // Accessors
|
Chris@16
|
154 // ---------
|
Chris@16
|
155
|
Chris@16
|
156 /// \brief Return the size of the vector
|
Chris@16
|
157 BOOST_UBLAS_INLINE
|
Chris@16
|
158 size_type size () const {
|
Chris@16
|
159 return data_.size ();
|
Chris@16
|
160 }
|
Chris@16
|
161
|
Chris@16
|
162 // -----------------
|
Chris@16
|
163 // Storage accessors
|
Chris@16
|
164 // -----------------
|
Chris@16
|
165
|
Chris@16
|
166 /// \brief Return a \c const reference to the container. Useful to access data directly for specific type of container.
|
Chris@16
|
167 BOOST_UBLAS_INLINE
|
Chris@16
|
168 const array_type &data () const {
|
Chris@16
|
169 return data_;
|
Chris@16
|
170 }
|
Chris@16
|
171
|
Chris@16
|
172 /// \brief Return a reference to the container. Useful to speed-up write operations to the data in very specific case.
|
Chris@16
|
173 BOOST_UBLAS_INLINE
|
Chris@16
|
174 array_type &data () {
|
Chris@16
|
175 return data_;
|
Chris@16
|
176 }
|
Chris@16
|
177
|
Chris@16
|
178 // --------
|
Chris@16
|
179 // Resizing
|
Chris@16
|
180 // --------
|
Chris@16
|
181
|
Chris@16
|
182 /// \brief Resize the vector
|
Chris@16
|
183 /// Resize the vector to a new size. If \c preserve is true, data are copied otherwise data are lost. If the new size is bigger, the remaining values are filled in with the initial value (0 by default) in the case of \c unbounded_array, which is the container by default. If the new size is smaller, last values are lost. This behaviour can be different if you explicitely specify another type of container.
|
Chris@16
|
184 /// \param size new size of the vector
|
Chris@16
|
185 /// \param preserve if true, keep values
|
Chris@16
|
186 BOOST_UBLAS_INLINE
|
Chris@16
|
187 void resize (size_type size, bool preserve = true) {
|
Chris@16
|
188 if (preserve)
|
Chris@16
|
189 data ().resize (size, typename A::value_type ());
|
Chris@16
|
190 else
|
Chris@16
|
191 data ().resize (size);
|
Chris@16
|
192 }
|
Chris@16
|
193
|
Chris@16
|
194 // ---------------
|
Chris@16
|
195 // Element support
|
Chris@16
|
196 // ---------------
|
Chris@16
|
197
|
Chris@16
|
198 /// \brief Return a pointer to the element \f$i\f$
|
Chris@16
|
199 /// \param i index of the element
|
Chris@16
|
200 // XXX this semantic is not the one expected by the name of this method
|
Chris@16
|
201 BOOST_UBLAS_INLINE
|
Chris@16
|
202 pointer find_element (size_type i) {
|
Chris@16
|
203 return const_cast<pointer> (const_cast<const self_type&>(*this).find_element (i));
|
Chris@16
|
204 }
|
Chris@16
|
205
|
Chris@16
|
206 /// \brief Return a const pointer to the element \f$i\f$
|
Chris@16
|
207 /// \param i index of the element
|
Chris@16
|
208 // XXX this semantic is not the one expected by the name of this method
|
Chris@16
|
209 BOOST_UBLAS_INLINE
|
Chris@16
|
210 const_pointer find_element (size_type i) const {
|
Chris@16
|
211 return & (data () [i]);
|
Chris@16
|
212 }
|
Chris@16
|
213
|
Chris@16
|
214 // --------------
|
Chris@16
|
215 // Element access
|
Chris@16
|
216 // --------------
|
Chris@16
|
217
|
Chris@16
|
218 /// \brief Return a const reference to the element \f$i\f$
|
Chris@16
|
219 /// Return a const reference to the element \f$i\f$. With some compilers, this notation will be faster than \c[i]
|
Chris@16
|
220 /// \param i index of the element
|
Chris@16
|
221 BOOST_UBLAS_INLINE
|
Chris@16
|
222 const_reference operator () (size_type i) const {
|
Chris@16
|
223 return data () [i];
|
Chris@16
|
224 }
|
Chris@16
|
225
|
Chris@16
|
226 /// \brief Return a reference to the element \f$i\f$
|
Chris@16
|
227 /// Return a reference to the element \f$i\f$. With some compilers, this notation will be faster than \c[i]
|
Chris@16
|
228 /// \param i index of the element
|
Chris@16
|
229 BOOST_UBLAS_INLINE
|
Chris@16
|
230 reference operator () (size_type i) {
|
Chris@16
|
231 return data () [i];
|
Chris@16
|
232 }
|
Chris@16
|
233
|
Chris@16
|
234 /// \brief Return a const reference to the element \f$i\f$
|
Chris@16
|
235 /// \param i index of the element
|
Chris@16
|
236 BOOST_UBLAS_INLINE
|
Chris@16
|
237 const_reference operator [] (size_type i) const {
|
Chris@16
|
238 return (*this) (i);
|
Chris@16
|
239 }
|
Chris@16
|
240
|
Chris@16
|
241 /// \brief Return a reference to the element \f$i\f$
|
Chris@16
|
242 /// \param i index of the element
|
Chris@16
|
243 BOOST_UBLAS_INLINE
|
Chris@16
|
244 reference operator [] (size_type i) {
|
Chris@16
|
245 return (*this) (i);
|
Chris@16
|
246 }
|
Chris@16
|
247
|
Chris@16
|
248 // ------------------
|
Chris@16
|
249 // Element assignment
|
Chris@16
|
250 // ------------------
|
Chris@16
|
251
|
Chris@16
|
252 /// \brief Set element \f$i\f$ to the value \c t
|
Chris@16
|
253 /// \param i index of the element
|
Chris@16
|
254 /// \param t reference to the value to be set
|
Chris@16
|
255 // XXX semantic of this is to insert a new element and therefore size=size+1 ?
|
Chris@16
|
256 BOOST_UBLAS_INLINE
|
Chris@16
|
257 reference insert_element (size_type i, const_reference t) {
|
Chris@16
|
258 return (data () [i] = t);
|
Chris@16
|
259 }
|
Chris@16
|
260
|
Chris@16
|
261 /// \brief Set element \f$i\f$ to the \e zero value
|
Chris@16
|
262 /// \param i index of the element
|
Chris@16
|
263 BOOST_UBLAS_INLINE
|
Chris@16
|
264 void erase_element (size_type i) {
|
Chris@16
|
265 data () [i] = value_type/*zero*/();
|
Chris@16
|
266 }
|
Chris@16
|
267
|
Chris@16
|
268 // -------
|
Chris@16
|
269 // Zeroing
|
Chris@16
|
270 // -------
|
Chris@16
|
271
|
Chris@16
|
272 /// \brief Clear the vector, i.e. set all values to the \c zero value.
|
Chris@16
|
273 BOOST_UBLAS_INLINE
|
Chris@16
|
274 void clear () {
|
Chris@16
|
275 std::fill (data ().begin (), data ().end (), value_type/*zero*/());
|
Chris@16
|
276 }
|
Chris@16
|
277
|
Chris@16
|
278 // Assignment
|
Chris@16
|
279 #ifdef BOOST_UBLAS_MOVE_SEMANTICS
|
Chris@16
|
280
|
Chris@16
|
281 /// \brief Assign a full vector (\e RHS-vector) to the current vector (\e LHS-vector)
|
Chris@16
|
282 /// \param v is the source vector
|
Chris@16
|
283 /// \return a reference to a vector (i.e. the destination vector)
|
Chris@16
|
284 /*! @note "pass by value" the key idea to enable move semantics */
|
Chris@16
|
285 BOOST_UBLAS_INLINE
|
Chris@16
|
286 vector &operator = (vector v) {
|
Chris@16
|
287 assign_temporary(v);
|
Chris@16
|
288 return *this;
|
Chris@16
|
289 }
|
Chris@16
|
290 #else
|
Chris@16
|
291 /// \brief Assign a full vector (\e RHS-vector) to the current vector (\e LHS-vector)
|
Chris@16
|
292 /// \param v is the source vector
|
Chris@16
|
293 /// \return a reference to a vector (i.e. the destination vector)
|
Chris@16
|
294 BOOST_UBLAS_INLINE
|
Chris@16
|
295 vector &operator = (const vector &v) {
|
Chris@16
|
296 data () = v.data ();
|
Chris@16
|
297 return *this;
|
Chris@16
|
298 }
|
Chris@16
|
299 #endif
|
Chris@16
|
300
|
Chris@16
|
301 /// \brief Assign a full vector (\e RHS-vector) to the current vector (\e LHS-vector)
|
Chris@16
|
302 /// Assign a full vector (\e RHS-vector) to the current vector (\e LHS-vector). This method does not create any temporary.
|
Chris@16
|
303 /// \param v is the source vector container
|
Chris@16
|
304 /// \return a reference to a vector (i.e. the destination vector)
|
Chris@16
|
305 template<class C> // Container assignment without temporary
|
Chris@16
|
306 BOOST_UBLAS_INLINE
|
Chris@16
|
307 vector &operator = (const vector_container<C> &v) {
|
Chris@16
|
308 resize (v ().size (), false);
|
Chris@16
|
309 assign (v);
|
Chris@16
|
310 return *this;
|
Chris@16
|
311 }
|
Chris@16
|
312
|
Chris@16
|
313 /// \brief Assign a full vector (\e RHS-vector) to the current vector (\e LHS-vector)
|
Chris@16
|
314 /// \param v is the source vector
|
Chris@16
|
315 /// \return a reference to a vector (i.e. the destination vector)
|
Chris@16
|
316 BOOST_UBLAS_INLINE
|
Chris@16
|
317 vector &assign_temporary (vector &v) {
|
Chris@16
|
318 swap (v);
|
Chris@16
|
319 return *this;
|
Chris@16
|
320 }
|
Chris@16
|
321
|
Chris@16
|
322 /// \brief Assign the result of a vector_expression to the vector
|
Chris@16
|
323 /// Assign the result of a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
324 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
325 /// \param ae is a const reference to the vector_expression
|
Chris@16
|
326 /// \return a reference to the resulting vector
|
Chris@16
|
327 template<class AE>
|
Chris@16
|
328 BOOST_UBLAS_INLINE
|
Chris@16
|
329 vector &operator = (const vector_expression<AE> &ae) {
|
Chris@16
|
330 self_type temporary (ae);
|
Chris@16
|
331 return assign_temporary (temporary);
|
Chris@16
|
332 }
|
Chris@16
|
333
|
Chris@16
|
334 /// \brief Assign the result of a vector_expression to the vector
|
Chris@16
|
335 /// Assign the result of a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
336 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
337 /// \param ae is a const reference to the vector_expression
|
Chris@16
|
338 /// \return a reference to the resulting vector
|
Chris@16
|
339 template<class AE>
|
Chris@16
|
340 BOOST_UBLAS_INLINE
|
Chris@16
|
341 vector &assign (const vector_expression<AE> &ae) {
|
Chris@16
|
342 vector_assign<scalar_assign> (*this, ae);
|
Chris@16
|
343 return *this;
|
Chris@16
|
344 }
|
Chris@16
|
345
|
Chris@16
|
346 // -------------------
|
Chris@16
|
347 // Computed assignment
|
Chris@16
|
348 // -------------------
|
Chris@16
|
349
|
Chris@16
|
350 /// \brief Assign the sum of the vector and a vector_expression to the vector
|
Chris@16
|
351 /// Assign the sum of the vector and a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
352 /// A temporary is created for the computations.
|
Chris@16
|
353 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
354 /// \param ae is a const reference to the vector_expression
|
Chris@16
|
355 /// \return a reference to the resulting vector
|
Chris@16
|
356 template<class AE>
|
Chris@16
|
357 BOOST_UBLAS_INLINE
|
Chris@16
|
358 vector &operator += (const vector_expression<AE> &ae) {
|
Chris@16
|
359 self_type temporary (*this + ae);
|
Chris@16
|
360 return assign_temporary (temporary);
|
Chris@16
|
361 }
|
Chris@16
|
362
|
Chris@16
|
363 /// \brief Assign the sum of the vector and a vector_expression to the vector
|
Chris@16
|
364 /// Assign the sum of the vector and a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
365 /// No temporary is created. Computations are done and stored directly into the resulting vector.
|
Chris@16
|
366 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
367 /// \param ae is a const reference to the vector_expression
|
Chris@16
|
368 /// \return a reference to the resulting vector
|
Chris@16
|
369 template<class C> // Container assignment without temporary
|
Chris@16
|
370 BOOST_UBLAS_INLINE
|
Chris@16
|
371 vector &operator += (const vector_container<C> &v) {
|
Chris@16
|
372 plus_assign (v);
|
Chris@16
|
373 return *this;
|
Chris@16
|
374 }
|
Chris@16
|
375
|
Chris@16
|
376 /// \brief Assign the sum of the vector and a vector_expression to the vector
|
Chris@16
|
377 /// Assign the sum of the vector and a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
378 /// No temporary is created. Computations are done and stored directly into the resulting vector.
|
Chris@16
|
379 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
380 /// \param ae is a const reference to the vector_expression
|
Chris@16
|
381 /// \return a reference to the resulting vector
|
Chris@16
|
382 template<class AE>
|
Chris@16
|
383 BOOST_UBLAS_INLINE
|
Chris@16
|
384 vector &plus_assign (const vector_expression<AE> &ae) {
|
Chris@16
|
385 vector_assign<scalar_plus_assign> (*this, ae);
|
Chris@16
|
386 return *this;
|
Chris@16
|
387 }
|
Chris@16
|
388
|
Chris@16
|
389 /// \brief Assign the difference of the vector and a vector_expression to the vector
|
Chris@16
|
390 /// Assign the difference of the vector and a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
391 /// A temporary is created for the computations.
|
Chris@16
|
392 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
393 /// \param ae is a const reference to the vector_expression
|
Chris@16
|
394 template<class AE>
|
Chris@16
|
395 BOOST_UBLAS_INLINE
|
Chris@16
|
396 vector &operator -= (const vector_expression<AE> &ae) {
|
Chris@16
|
397 self_type temporary (*this - ae);
|
Chris@16
|
398 return assign_temporary (temporary);
|
Chris@16
|
399 }
|
Chris@16
|
400
|
Chris@16
|
401 /// \brief Assign the difference of the vector and a vector_expression to the vector
|
Chris@16
|
402 /// Assign the difference of the vector and a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
403 /// No temporary is created. Computations are done and stored directly into the resulting vector.
|
Chris@16
|
404 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
405 /// \param ae is a const reference to the vector_expression
|
Chris@16
|
406 /// \return a reference to the resulting vector
|
Chris@16
|
407 template<class C> // Container assignment without temporary
|
Chris@16
|
408 BOOST_UBLAS_INLINE
|
Chris@16
|
409 vector &operator -= (const vector_container<C> &v) {
|
Chris@16
|
410 minus_assign (v);
|
Chris@16
|
411 return *this;
|
Chris@16
|
412 }
|
Chris@16
|
413
|
Chris@16
|
414 /// \brief Assign the difference of the vector and a vector_expression to the vector
|
Chris@16
|
415 /// Assign the difference of the vector and a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
416 /// No temporary is created. Computations are done and stored directly into the resulting vector.
|
Chris@16
|
417 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
418 /// \param ae is a const reference to the vector_expression
|
Chris@16
|
419 /// \return a reference to the resulting vector
|
Chris@16
|
420 template<class AE>
|
Chris@16
|
421 BOOST_UBLAS_INLINE
|
Chris@16
|
422 vector &minus_assign (const vector_expression<AE> &ae) {
|
Chris@16
|
423 vector_assign<scalar_minus_assign> (*this, ae);
|
Chris@16
|
424 return *this;
|
Chris@16
|
425 }
|
Chris@16
|
426
|
Chris@16
|
427 /// \brief Assign the product of the vector and a scalar to the vector
|
Chris@16
|
428 /// Assign the product of the vector and a scalar to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
429 /// No temporary is created. Computations are done and stored directly into the resulting vector.
|
Chris@16
|
430 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
431 /// \param at is a const reference to the scalar
|
Chris@16
|
432 /// \return a reference to the resulting vector
|
Chris@16
|
433 template<class AT>
|
Chris@16
|
434 BOOST_UBLAS_INLINE
|
Chris@16
|
435 vector &operator *= (const AT &at) {
|
Chris@16
|
436 vector_assign_scalar<scalar_multiplies_assign> (*this, at);
|
Chris@16
|
437 return *this;
|
Chris@16
|
438 }
|
Chris@16
|
439
|
Chris@16
|
440 /// \brief Assign the division of the vector by a scalar to the vector
|
Chris@16
|
441 /// Assign the division of the vector by a scalar to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@16
|
442 /// No temporary is created. Computations are done and stored directly into the resulting vector.
|
Chris@16
|
443 /// \tparam AE is the type of the vector_expression
|
Chris@16
|
444 /// \param at is a const reference to the scalar
|
Chris@16
|
445 /// \return a reference to the resulting vector
|
Chris@16
|
446 template<class AT>
|
Chris@16
|
447 BOOST_UBLAS_INLINE
|
Chris@16
|
448 vector &operator /= (const AT &at) {
|
Chris@16
|
449 vector_assign_scalar<scalar_divides_assign> (*this, at);
|
Chris@16
|
450 return *this;
|
Chris@16
|
451 }
|
Chris@16
|
452
|
Chris@16
|
453 // --------
|
Chris@16
|
454 // Swapping
|
Chris@16
|
455 // --------
|
Chris@16
|
456
|
Chris@16
|
457 /// \brief Swap the content of the vector with another vector
|
Chris@16
|
458 /// \param v is the vector to be swapped with
|
Chris@16
|
459 BOOST_UBLAS_INLINE
|
Chris@16
|
460 void swap (vector &v) {
|
Chris@16
|
461 if (this != &v) {
|
Chris@16
|
462 data ().swap (v.data ());
|
Chris@16
|
463 }
|
Chris@16
|
464 }
|
Chris@16
|
465
|
Chris@16
|
466 /// \brief Swap the content of two vectors
|
Chris@16
|
467 /// \param v1 is the first vector. It takes values from v2
|
Chris@16
|
468 /// \param v2 is the second vector It takes values from v1
|
Chris@16
|
469 BOOST_UBLAS_INLINE
|
Chris@16
|
470 friend void swap (vector &v1, vector &v2) {
|
Chris@16
|
471 v1.swap (v2);
|
Chris@16
|
472 }
|
Chris@16
|
473
|
Chris@16
|
474 // Iterator types
|
Chris@16
|
475 private:
|
Chris@16
|
476 // Use the storage array iterator
|
Chris@16
|
477 typedef typename A::const_iterator const_subiterator_type;
|
Chris@16
|
478 typedef typename A::iterator subiterator_type;
|
Chris@16
|
479
|
Chris@16
|
480 public:
|
Chris@16
|
481 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
482 typedef indexed_iterator<self_type, dense_random_access_iterator_tag> iterator;
|
Chris@16
|
483 typedef indexed_const_iterator<self_type, dense_random_access_iterator_tag> const_iterator;
|
Chris@16
|
484 #else
|
Chris@16
|
485 class const_iterator;
|
Chris@16
|
486 class iterator;
|
Chris@16
|
487 #endif
|
Chris@16
|
488
|
Chris@16
|
489 // --------------
|
Chris@16
|
490 // Element lookup
|
Chris@16
|
491 // --------------
|
Chris@16
|
492
|
Chris@16
|
493 /// \brief Return a const iterator to the element \e i
|
Chris@16
|
494 /// \param i index of the element
|
Chris@16
|
495 BOOST_UBLAS_INLINE
|
Chris@16
|
496 const_iterator find (size_type i) const {
|
Chris@16
|
497 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
498 return const_iterator (*this, data ().begin () + i);
|
Chris@16
|
499 #else
|
Chris@16
|
500 return const_iterator (*this, i);
|
Chris@16
|
501 #endif
|
Chris@16
|
502 }
|
Chris@16
|
503
|
Chris@16
|
504 /// \brief Return an iterator to the element \e i
|
Chris@16
|
505 /// \param i index of the element
|
Chris@16
|
506 BOOST_UBLAS_INLINE
|
Chris@16
|
507 iterator find (size_type i) {
|
Chris@16
|
508 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
509 return iterator (*this, data ().begin () + i);
|
Chris@16
|
510 #else
|
Chris@16
|
511 return iterator (*this, i);
|
Chris@16
|
512 #endif
|
Chris@16
|
513 }
|
Chris@16
|
514
|
Chris@16
|
515 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
516 class const_iterator:
|
Chris@16
|
517 public container_const_reference<vector>,
|
Chris@16
|
518 public random_access_iterator_base<dense_random_access_iterator_tag,
|
Chris@16
|
519 const_iterator, value_type, difference_type> {
|
Chris@16
|
520 public:
|
Chris@16
|
521 typedef typename vector::difference_type difference_type;
|
Chris@16
|
522 typedef typename vector::value_type value_type;
|
Chris@16
|
523 typedef typename vector::const_reference reference;
|
Chris@16
|
524 typedef const typename vector::pointer pointer;
|
Chris@16
|
525
|
Chris@16
|
526 // ----------------------------
|
Chris@16
|
527 // Construction and destruction
|
Chris@16
|
528 // ----------------------------
|
Chris@16
|
529
|
Chris@16
|
530
|
Chris@16
|
531 BOOST_UBLAS_INLINE
|
Chris@16
|
532 const_iterator ():
|
Chris@16
|
533 container_const_reference<self_type> (), it_ () {}
|
Chris@16
|
534 BOOST_UBLAS_INLINE
|
Chris@16
|
535 const_iterator (const self_type &v, const const_subiterator_type &it):
|
Chris@16
|
536 container_const_reference<self_type> (v), it_ (it) {}
|
Chris@16
|
537 BOOST_UBLAS_INLINE
|
Chris@16
|
538 const_iterator (const typename self_type::iterator &it): // ISSUE vector:: stops VC8 using std::iterator here
|
Chris@16
|
539 container_const_reference<self_type> (it ()), it_ (it.it_) {}
|
Chris@16
|
540
|
Chris@16
|
541 // ----------
|
Chris@16
|
542 // Arithmetic
|
Chris@16
|
543 // ----------
|
Chris@16
|
544
|
Chris@16
|
545 /// \brief Increment by 1 the position of the iterator
|
Chris@16
|
546 /// \return a reference to the const iterator
|
Chris@16
|
547 BOOST_UBLAS_INLINE
|
Chris@16
|
548 const_iterator &operator ++ () {
|
Chris@16
|
549 ++ it_;
|
Chris@16
|
550 return *this;
|
Chris@16
|
551 }
|
Chris@16
|
552
|
Chris@16
|
553 /// \brief Decrement by 1 the position of the iterator
|
Chris@16
|
554 /// \return a reference to the const iterator
|
Chris@16
|
555 BOOST_UBLAS_INLINE
|
Chris@16
|
556 const_iterator &operator -- () {
|
Chris@16
|
557 -- it_;
|
Chris@16
|
558 return *this;
|
Chris@16
|
559 }
|
Chris@16
|
560
|
Chris@16
|
561 /// \brief Increment by \e n the position of the iterator
|
Chris@16
|
562 /// \return a reference to the const iterator
|
Chris@16
|
563 BOOST_UBLAS_INLINE
|
Chris@16
|
564 const_iterator &operator += (difference_type n) {
|
Chris@16
|
565 it_ += n;
|
Chris@16
|
566 return *this;
|
Chris@16
|
567 }
|
Chris@16
|
568
|
Chris@16
|
569 /// \brief Decrement by \e n the position of the iterator
|
Chris@16
|
570 /// \return a reference to the const iterator
|
Chris@16
|
571 BOOST_UBLAS_INLINE
|
Chris@16
|
572 const_iterator &operator -= (difference_type n) {
|
Chris@16
|
573 it_ -= n;
|
Chris@16
|
574 return *this;
|
Chris@16
|
575 }
|
Chris@16
|
576
|
Chris@16
|
577 /// \brief Return the different in number of positions between 2 iterators
|
Chris@16
|
578 BOOST_UBLAS_INLINE
|
Chris@16
|
579 difference_type operator - (const const_iterator &it) const {
|
Chris@16
|
580 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
581 return it_ - it.it_;
|
Chris@16
|
582 }
|
Chris@16
|
583
|
Chris@16
|
584 /// \brief Dereference an iterator
|
Chris@16
|
585 /// Dereference an iterator: a bounds' check is done before returning the value. A bad_index() expection is returned if out of bounds.
|
Chris@16
|
586 /// \return a const reference to the value pointed by the iterator
|
Chris@16
|
587 BOOST_UBLAS_INLINE
|
Chris@16
|
588 const_reference operator * () const {
|
Chris@16
|
589 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
|
Chris@16
|
590 return *it_;
|
Chris@16
|
591 }
|
Chris@16
|
592
|
Chris@16
|
593 /// \brief Dereference an iterator at the n-th forward value
|
Chris@16
|
594 /// Dereference an iterator at the n-th forward value, that is the value pointed by iterator+n.
|
Chris@16
|
595 /// A bounds' check is done before returning the value. A bad_index() expection is returned if out of bounds.
|
Chris@16
|
596 /// \return a const reference
|
Chris@16
|
597 BOOST_UBLAS_INLINE
|
Chris@16
|
598 const_reference operator [] (difference_type n) const {
|
Chris@16
|
599 return *(it_ + n);
|
Chris@16
|
600 }
|
Chris@16
|
601
|
Chris@16
|
602 // Index
|
Chris@16
|
603 /// \brief return the index of the element referenced by the iterator
|
Chris@16
|
604 BOOST_UBLAS_INLINE
|
Chris@16
|
605 size_type index () const {
|
Chris@16
|
606 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
|
Chris@16
|
607 return it_ - (*this) ().begin ().it_;
|
Chris@16
|
608 }
|
Chris@16
|
609
|
Chris@16
|
610 // Assignment
|
Chris@16
|
611 BOOST_UBLAS_INLINE
|
Chris@16
|
612 /// \brief assign the value of an iterator to the iterator
|
Chris@16
|
613 const_iterator &operator = (const const_iterator &it) {
|
Chris@16
|
614 container_const_reference<self_type>::assign (&it ());
|
Chris@16
|
615 it_ = it.it_;
|
Chris@16
|
616 return *this;
|
Chris@16
|
617 }
|
Chris@16
|
618
|
Chris@16
|
619 // Comparison
|
Chris@16
|
620 /// \brief compare the value of two itetarors
|
Chris@16
|
621 /// \return true if they reference the same element
|
Chris@16
|
622 BOOST_UBLAS_INLINE
|
Chris@16
|
623 bool operator == (const const_iterator &it) const {
|
Chris@16
|
624 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
625 return it_ == it.it_;
|
Chris@16
|
626 }
|
Chris@16
|
627
|
Chris@16
|
628
|
Chris@16
|
629 /// \brief compare the value of two iterators
|
Chris@16
|
630 /// \return return true if the left-hand-side iterator refers to a value placed before the right-hand-side iterator
|
Chris@16
|
631 BOOST_UBLAS_INLINE
|
Chris@16
|
632 bool operator < (const const_iterator &it) const {
|
Chris@16
|
633 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
634 return it_ < it.it_;
|
Chris@16
|
635 }
|
Chris@16
|
636
|
Chris@16
|
637 private:
|
Chris@16
|
638 const_subiterator_type it_;
|
Chris@16
|
639
|
Chris@16
|
640 friend class iterator;
|
Chris@16
|
641 };
|
Chris@16
|
642 #endif
|
Chris@16
|
643
|
Chris@16
|
644 /// \brief return an iterator on the first element of the vector
|
Chris@16
|
645 BOOST_UBLAS_INLINE
|
Chris@16
|
646 const_iterator begin () const {
|
Chris@16
|
647 return find (0);
|
Chris@16
|
648 }
|
Chris@16
|
649
|
Chris@101
|
650 /// \brief return an iterator on the first element of the vector
|
Chris@101
|
651 BOOST_UBLAS_INLINE
|
Chris@101
|
652 const_iterator cbegin () const {
|
Chris@101
|
653 return begin ();
|
Chris@101
|
654 }
|
Chris@101
|
655
|
Chris@16
|
656 /// \brief return an iterator after the last element of the vector
|
Chris@101
|
657 BOOST_UBLAS_INLINE
|
Chris@101
|
658 const_iterator end () const {
|
Chris@101
|
659 return find (data_.size ());
|
Chris@101
|
660 }
|
Chris@101
|
661
|
Chris@101
|
662 /// \brief return an iterator after the last element of the vector
|
Chris@101
|
663 BOOST_UBLAS_INLINE
|
Chris@101
|
664 const_iterator cend () const {
|
Chris@101
|
665 return end ();
|
Chris@101
|
666 }
|
Chris@16
|
667
|
Chris@16
|
668 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
669 class iterator:
|
Chris@16
|
670 public container_reference<vector>,
|
Chris@16
|
671 public random_access_iterator_base<dense_random_access_iterator_tag,
|
Chris@16
|
672 iterator, value_type, difference_type> {
|
Chris@16
|
673 public:
|
Chris@16
|
674 typedef typename vector::difference_type difference_type;
|
Chris@16
|
675 typedef typename vector::value_type value_type;
|
Chris@16
|
676 typedef typename vector::reference reference;
|
Chris@16
|
677 typedef typename vector::pointer pointer;
|
Chris@16
|
678
|
Chris@16
|
679
|
Chris@16
|
680 // Construction and destruction
|
Chris@16
|
681 BOOST_UBLAS_INLINE
|
Chris@16
|
682 iterator ():
|
Chris@16
|
683 container_reference<self_type> (), it_ () {}
|
Chris@16
|
684 BOOST_UBLAS_INLINE
|
Chris@16
|
685 iterator (self_type &v, const subiterator_type &it):
|
Chris@16
|
686 container_reference<self_type> (v), it_ (it) {}
|
Chris@16
|
687
|
Chris@16
|
688 // Arithmetic
|
Chris@16
|
689 BOOST_UBLAS_INLINE
|
Chris@16
|
690 iterator &operator ++ () {
|
Chris@16
|
691 ++ it_;
|
Chris@16
|
692 return *this;
|
Chris@16
|
693 }
|
Chris@16
|
694 BOOST_UBLAS_INLINE
|
Chris@16
|
695 iterator &operator -- () {
|
Chris@16
|
696 -- it_;
|
Chris@16
|
697 return *this;
|
Chris@16
|
698 }
|
Chris@16
|
699 BOOST_UBLAS_INLINE
|
Chris@16
|
700 iterator &operator += (difference_type n) {
|
Chris@16
|
701 it_ += n;
|
Chris@16
|
702 return *this;
|
Chris@16
|
703 }
|
Chris@16
|
704 BOOST_UBLAS_INLINE
|
Chris@16
|
705 iterator &operator -= (difference_type n) {
|
Chris@16
|
706 it_ -= n;
|
Chris@16
|
707 return *this;
|
Chris@16
|
708 }
|
Chris@16
|
709 BOOST_UBLAS_INLINE
|
Chris@16
|
710 difference_type operator - (const iterator &it) const {
|
Chris@16
|
711 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
712 return it_ - it.it_;
|
Chris@16
|
713 }
|
Chris@16
|
714
|
Chris@16
|
715 // Dereference
|
Chris@16
|
716 BOOST_UBLAS_INLINE
|
Chris@16
|
717 reference operator * () const {
|
Chris@16
|
718 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_ , bad_index ());
|
Chris@16
|
719 return *it_;
|
Chris@16
|
720 }
|
Chris@16
|
721 BOOST_UBLAS_INLINE
|
Chris@16
|
722 reference operator [] (difference_type n) const {
|
Chris@16
|
723 return *(it_ + n);
|
Chris@16
|
724 }
|
Chris@16
|
725
|
Chris@16
|
726 // Index
|
Chris@16
|
727 BOOST_UBLAS_INLINE
|
Chris@16
|
728 size_type index () const {
|
Chris@16
|
729 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_ , bad_index ());
|
Chris@16
|
730 return it_ - (*this) ().begin ().it_;
|
Chris@16
|
731 }
|
Chris@16
|
732
|
Chris@16
|
733 // Assignment
|
Chris@16
|
734 BOOST_UBLAS_INLINE
|
Chris@16
|
735 iterator &operator = (const iterator &it) {
|
Chris@16
|
736 container_reference<self_type>::assign (&it ());
|
Chris@16
|
737 it_ = it.it_;
|
Chris@16
|
738 return *this;
|
Chris@16
|
739 }
|
Chris@16
|
740
|
Chris@16
|
741 // Comparison
|
Chris@16
|
742 BOOST_UBLAS_INLINE
|
Chris@16
|
743 bool operator == (const iterator &it) const {
|
Chris@16
|
744 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
745 return it_ == it.it_;
|
Chris@16
|
746 }
|
Chris@16
|
747 BOOST_UBLAS_INLINE
|
Chris@16
|
748 bool operator < (const iterator &it) const {
|
Chris@16
|
749 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
750 return it_ < it.it_;
|
Chris@16
|
751 }
|
Chris@16
|
752
|
Chris@16
|
753 private:
|
Chris@16
|
754 subiterator_type it_;
|
Chris@16
|
755
|
Chris@16
|
756 friend class const_iterator;
|
Chris@16
|
757 };
|
Chris@16
|
758 #endif
|
Chris@16
|
759
|
Chris@16
|
760 /// \brief Return an iterator on the first element of the vector
|
Chris@16
|
761 BOOST_UBLAS_INLINE
|
Chris@16
|
762 iterator begin () {
|
Chris@16
|
763 return find (0);
|
Chris@16
|
764 }
|
Chris@16
|
765
|
Chris@16
|
766 /// \brief Return an iterator at the end of the vector
|
Chris@16
|
767 BOOST_UBLAS_INLINE
|
Chris@16
|
768 iterator end () {
|
Chris@16
|
769 return find (data_.size ());
|
Chris@16
|
770 }
|
Chris@16
|
771
|
Chris@16
|
772 // Reverse iterator
|
Chris@16
|
773 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
|
Chris@16
|
774 typedef reverse_iterator_base<iterator> reverse_iterator;
|
Chris@16
|
775
|
Chris@16
|
776 /// \brief Return a const reverse iterator before the first element of the reversed vector (i.e. end() of normal vector)
|
Chris@16
|
777 BOOST_UBLAS_INLINE
|
Chris@16
|
778 const_reverse_iterator rbegin () const {
|
Chris@16
|
779 return const_reverse_iterator (end ());
|
Chris@16
|
780 }
|
Chris@16
|
781
|
Chris@101
|
782 /// \brief Return a const reverse iterator before the first element of the reversed vector (i.e. end() of normal vector)
|
Chris@101
|
783 BOOST_UBLAS_INLINE
|
Chris@101
|
784 const_reverse_iterator crbegin () const {
|
Chris@101
|
785 return rbegin ();
|
Chris@101
|
786 }
|
Chris@101
|
787
|
Chris@16
|
788 /// \brief Return a const reverse iterator on the end of the reverse vector (i.e. first element of the normal vector)
|
Chris@16
|
789 BOOST_UBLAS_INLINE
|
Chris@16
|
790 const_reverse_iterator rend () const {
|
Chris@16
|
791 return const_reverse_iterator (begin ());
|
Chris@16
|
792 }
|
Chris@16
|
793
|
Chris@101
|
794 /// \brief Return a const reverse iterator on the end of the reverse vector (i.e. first element of the normal vector)
|
Chris@101
|
795 BOOST_UBLAS_INLINE
|
Chris@101
|
796 const_reverse_iterator crend () const {
|
Chris@101
|
797 return rend ();
|
Chris@101
|
798 }
|
Chris@101
|
799
|
Chris@16
|
800 /// \brief Return a const reverse iterator before the first element of the reversed vector (i.e. end() of normal vector)
|
Chris@16
|
801 BOOST_UBLAS_INLINE
|
Chris@16
|
802 reverse_iterator rbegin () {
|
Chris@16
|
803 return reverse_iterator (end ());
|
Chris@16
|
804 }
|
Chris@16
|
805
|
Chris@16
|
806 /// \brief Return a const reverse iterator on the end of the reverse vector (i.e. first element of the normal vector)
|
Chris@16
|
807 BOOST_UBLAS_INLINE
|
Chris@16
|
808 reverse_iterator rend () {
|
Chris@16
|
809 return reverse_iterator (begin ());
|
Chris@16
|
810 }
|
Chris@16
|
811
|
Chris@16
|
812 // -------------
|
Chris@16
|
813 // Serialization
|
Chris@16
|
814 // -------------
|
Chris@16
|
815
|
Chris@16
|
816 /// Serialize a vector into and archive as defined in Boost
|
Chris@16
|
817 /// \param ar Archive object. Can be a flat file, an XML file or any other stream
|
Chris@16
|
818 /// \param file_version Optional file version (not yet used)
|
Chris@16
|
819 template<class Archive>
|
Chris@16
|
820 void serialize(Archive & ar, const unsigned int /* file_version */){
|
Chris@16
|
821 ar & serialization::make_nvp("data",data_);
|
Chris@16
|
822 }
|
Chris@16
|
823
|
Chris@16
|
824 private:
|
Chris@16
|
825 array_type data_;
|
Chris@16
|
826 };
|
Chris@16
|
827
|
Chris@16
|
828
|
Chris@101
|
829 #ifdef BOOST_UBLAS_CPP_GE_2011
|
Chris@101
|
830 /** \brief A dense vector of values of type \c T.
|
Chris@101
|
831 *
|
Chris@101
|
832 * For a \f$n\f$-dimensional vector \f$v\f$ and \f$0\leq i < n\f$ every element \f$v_i\f$ is mapped
|
Chris@101
|
833 * to the \f$i\f$-th element of the container. A storage type \c A can be specified which defaults to \c std::array.
|
Chris@101
|
834 * Elements are constructed by \c A, which need not initialise their value.
|
Chris@101
|
835 *
|
Chris@101
|
836 * \tparam T type of the objects stored in the vector (like int, double, complex,...)
|
Chris@101
|
837 * \tparam A The type of the storage array of the vector. Default is \c std::array<T>.
|
Chris@101
|
838 */
|
Chris@101
|
839 template<class T, std::size_t N, class A>
|
Chris@101
|
840 class fixed_vector:
|
Chris@101
|
841 public vector_container<fixed_vector<T, N, A> > {
|
Chris@101
|
842
|
Chris@101
|
843 typedef fixed_vector<T, N, A> self_type;
|
Chris@101
|
844 public:
|
Chris@101
|
845 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
|
Chris@101
|
846 using vector_container<self_type>::operator ();
|
Chris@101
|
847 #endif
|
Chris@101
|
848
|
Chris@101
|
849 typedef typename A::size_type size_type;
|
Chris@101
|
850 typedef typename A::difference_type difference_type;
|
Chris@101
|
851 typedef T value_type;
|
Chris@101
|
852 typedef typename type_traits<T>::const_reference const_reference;
|
Chris@101
|
853 typedef T &reference;
|
Chris@101
|
854 typedef T *pointer;
|
Chris@101
|
855 typedef const T *const_pointer;
|
Chris@101
|
856 typedef A array_type;
|
Chris@101
|
857 typedef const vector_reference<const self_type> const_closure_type;
|
Chris@101
|
858 typedef vector_reference<self_type> closure_type;
|
Chris@101
|
859 typedef self_type vector_temporary_type;
|
Chris@101
|
860 typedef dense_tag storage_category;
|
Chris@101
|
861
|
Chris@101
|
862 // Construction and destruction
|
Chris@101
|
863
|
Chris@101
|
864 /// \brief Constructor of a fixed_vector
|
Chris@101
|
865 BOOST_UBLAS_INLINE
|
Chris@101
|
866 fixed_vector ():
|
Chris@101
|
867 vector_container<self_type> (),
|
Chris@101
|
868 data_ () {}
|
Chris@101
|
869
|
Chris@101
|
870 /// \brief Constructor of a fixed_vector by copying from another container
|
Chris@101
|
871 /// This type uses the generic name \c array_type within the vector definition.
|
Chris@101
|
872 /// \param data container of type \c A
|
Chris@101
|
873 BOOST_UBLAS_INLINE
|
Chris@101
|
874 fixed_vector (const array_type &data):
|
Chris@101
|
875 vector_container<self_type> (),
|
Chris@101
|
876 data_ (data) {}
|
Chris@101
|
877
|
Chris@101
|
878 /// \brief Constructor of a fixed_vector with a unique initial value
|
Chris@101
|
879 /// \param init value to assign to each element of the vector
|
Chris@101
|
880 BOOST_UBLAS_INLINE
|
Chris@101
|
881 fixed_vector (const value_type &init):
|
Chris@101
|
882 vector_container<self_type> (),
|
Chris@101
|
883 data_ () {
|
Chris@101
|
884 data_.fill( init );
|
Chris@101
|
885 }
|
Chris@101
|
886
|
Chris@101
|
887 /// \brief Copy-constructor of a fixed_vector
|
Chris@101
|
888 /// \param v is the fixed_vector to be duplicated
|
Chris@101
|
889 BOOST_UBLAS_INLINE
|
Chris@101
|
890 fixed_vector (const fixed_vector &v):
|
Chris@101
|
891 vector_container<self_type> (),
|
Chris@101
|
892 data_ (v.data_) {}
|
Chris@101
|
893
|
Chris@101
|
894 /// \brief Copy-constructor of a vector from a vector_expression
|
Chris@101
|
895 /// Depending on the vector_expression, this constructor can have the cost of the computations
|
Chris@101
|
896 /// of the expression (trivial to say it, but take it must be taken into account in your complexity calculations).
|
Chris@101
|
897 /// \param ae the vector_expression which values will be duplicated into the vector
|
Chris@101
|
898 template<class AE>
|
Chris@101
|
899 BOOST_UBLAS_INLINE
|
Chris@101
|
900 fixed_vector (const vector_expression<AE> &ae):
|
Chris@101
|
901 vector_container<self_type> (),
|
Chris@101
|
902 data_ ( ) {
|
Chris@101
|
903 vector_assign<scalar_assign> (*this, ae);
|
Chris@101
|
904 }
|
Chris@101
|
905
|
Chris@101
|
906 /// \brief Construct a fixed_vector from a list of values
|
Chris@101
|
907 /// This constructor enables initialization by using any of:
|
Chris@101
|
908 /// fixed_vector<double, 3> v = { 1, 2, 3 } or fixed_vector<double,3> v( {1, 2, 3} ) or fixed_vector<double,3> v( 1, 2, 3 )
|
Chris@101
|
909 #if defined(BOOST_MSVC)
|
Chris@101
|
910 // This may or may not work. Maybe use this for all instead only for MSVC
|
Chris@101
|
911 template <typename... U>
|
Chris@101
|
912 fixed_vector(U&&... values) :
|
Chris@101
|
913 vector_container<self_type> (),
|
Chris@101
|
914 data_{{ std::forward<U>(values)... }} {}
|
Chris@101
|
915 #else
|
Chris@101
|
916 template <typename... Types>
|
Chris@101
|
917 fixed_vector(value_type v0, Types... vrest) :
|
Chris@101
|
918 vector_container<self_type> (),
|
Chris@101
|
919 data_{ { v0, vrest... } } {}
|
Chris@101
|
920 #endif
|
Chris@101
|
921
|
Chris@101
|
922 // -----------------------
|
Chris@101
|
923 // Random Access Container
|
Chris@101
|
924 // -----------------------
|
Chris@101
|
925
|
Chris@101
|
926 /// \brief Return the maximum size of the data container.
|
Chris@101
|
927 /// Return the upper bound (maximum size) on the data container. Depending on the container, it can be bigger than the current size of the vector.
|
Chris@101
|
928 BOOST_UBLAS_INLINE
|
Chris@101
|
929 size_type max_size () const {
|
Chris@101
|
930 return data_.max_size ();
|
Chris@101
|
931 }
|
Chris@101
|
932
|
Chris@101
|
933 /// \brief Return true if the vector is empty (\c size==0)
|
Chris@101
|
934 /// \return \c true if empty, \c false otherwise
|
Chris@101
|
935 BOOST_UBLAS_INLINE
|
Chris@101
|
936 const bool &empty () const {
|
Chris@101
|
937 return data_.empty();
|
Chris@101
|
938 }
|
Chris@101
|
939
|
Chris@101
|
940 // ---------
|
Chris@101
|
941 // Accessors
|
Chris@101
|
942 // ---------
|
Chris@101
|
943
|
Chris@101
|
944 /// \brief Return the size of the vector
|
Chris@101
|
945 BOOST_UBLAS_INLINE
|
Chris@101
|
946 BOOST_CONSTEXPR size_type size () const{ // should have a const after C++14
|
Chris@101
|
947 return data_.size ();
|
Chris@101
|
948 }
|
Chris@101
|
949
|
Chris@101
|
950 // -----------------
|
Chris@101
|
951 // Storage accessors
|
Chris@101
|
952 // -----------------
|
Chris@101
|
953
|
Chris@101
|
954 /// \brief Return a \c const reference to the container. Useful to access data directly for specific type of container.
|
Chris@101
|
955 BOOST_UBLAS_INLINE
|
Chris@101
|
956 const array_type &data () const {
|
Chris@101
|
957 return data_;
|
Chris@101
|
958 }
|
Chris@101
|
959
|
Chris@101
|
960 /// \brief Return a reference to the container. Useful to speed-up write operations to the data in very specific case.
|
Chris@101
|
961 BOOST_UBLAS_INLINE
|
Chris@101
|
962 array_type &data () {
|
Chris@101
|
963 return data_;
|
Chris@101
|
964 }
|
Chris@101
|
965
|
Chris@101
|
966 // ---------------
|
Chris@101
|
967 // Element support
|
Chris@101
|
968 // ---------------
|
Chris@101
|
969
|
Chris@101
|
970 /// \brief Return a pointer to the element \f$i\f$
|
Chris@101
|
971 /// \param i index of the element
|
Chris@101
|
972 // XXX this semantic is not the one expected by the name of this method
|
Chris@101
|
973 BOOST_UBLAS_INLINE
|
Chris@101
|
974 pointer find_element (size_type i) {
|
Chris@101
|
975 return const_cast<pointer> (const_cast<const self_type&>(*this).find_element (i));
|
Chris@101
|
976 }
|
Chris@101
|
977
|
Chris@101
|
978 /// \brief Return a const pointer to the element \f$i\f$
|
Chris@101
|
979 /// \param i index of the element
|
Chris@101
|
980 // XXX this semantic is not the one expected by the name of this method
|
Chris@101
|
981 BOOST_UBLAS_INLINE
|
Chris@101
|
982 const_pointer find_element (size_type i) const {
|
Chris@101
|
983 BOOST_UBLAS_CHECK (i < data_.size(), bad_index() ); // Since std:array doesn't check for bounds
|
Chris@101
|
984 return & (data () [i]);
|
Chris@101
|
985 }
|
Chris@101
|
986
|
Chris@101
|
987 // --------------
|
Chris@101
|
988 // Element access
|
Chris@101
|
989 // --------------
|
Chris@101
|
990
|
Chris@101
|
991 /// \brief Return a const reference to the element \f$i\f$
|
Chris@101
|
992 /// Return a const reference to the element \f$i\f$. With some compilers, this notation will be faster than \c[i]
|
Chris@101
|
993 /// \param i index of the element
|
Chris@101
|
994 BOOST_UBLAS_INLINE
|
Chris@101
|
995 const_reference operator () (size_type i) const {
|
Chris@101
|
996 BOOST_UBLAS_CHECK (i < data_.size(), bad_index() );
|
Chris@101
|
997 return data () [i];
|
Chris@101
|
998 }
|
Chris@101
|
999
|
Chris@101
|
1000 /// \brief Return a reference to the element \f$i\f$
|
Chris@101
|
1001 /// Return a reference to the element \f$i\f$. With some compilers, this notation will be faster than \c[i]
|
Chris@101
|
1002 /// \param i index of the element
|
Chris@101
|
1003 BOOST_UBLAS_INLINE
|
Chris@101
|
1004 reference operator () (size_type i) {
|
Chris@101
|
1005 BOOST_UBLAS_CHECK (i < data_.size(), bad_index() );
|
Chris@101
|
1006 return data () [i];
|
Chris@101
|
1007 }
|
Chris@101
|
1008
|
Chris@101
|
1009 /// \brief Return a const reference to the element \f$i\f$
|
Chris@101
|
1010 /// \param i index of the element
|
Chris@101
|
1011 BOOST_UBLAS_INLINE
|
Chris@101
|
1012 const_reference operator [] (size_type i) const {
|
Chris@101
|
1013 BOOST_UBLAS_CHECK (i < data_.size(), bad_index() );
|
Chris@101
|
1014 return (*this) (i);
|
Chris@101
|
1015 }
|
Chris@101
|
1016
|
Chris@101
|
1017 /// \brief Return a reference to the element \f$i\f$
|
Chris@101
|
1018 /// \param i index of the element
|
Chris@101
|
1019 BOOST_UBLAS_INLINE
|
Chris@101
|
1020 reference operator [] (size_type i) {
|
Chris@101
|
1021 BOOST_UBLAS_CHECK (i < data_.size(), bad_index() );
|
Chris@101
|
1022 return (*this) (i);
|
Chris@101
|
1023 }
|
Chris@101
|
1024
|
Chris@101
|
1025 // ------------------
|
Chris@101
|
1026 // Element assignment
|
Chris@101
|
1027 // ------------------
|
Chris@101
|
1028
|
Chris@101
|
1029 /// \brief Set element \f$i\f$ to the value \c t
|
Chris@101
|
1030 /// \param i index of the element
|
Chris@101
|
1031 /// \param t reference to the value to be set
|
Chris@101
|
1032 // XXX semantic of this is to insert a new element and therefore size=size+1 ?
|
Chris@101
|
1033 BOOST_UBLAS_INLINE
|
Chris@101
|
1034 reference insert_element (size_type i, const_reference t) {
|
Chris@101
|
1035 BOOST_UBLAS_CHECK (i < data_.size(), bad_index ());
|
Chris@101
|
1036 return (data () [i] = t);
|
Chris@101
|
1037 }
|
Chris@101
|
1038
|
Chris@101
|
1039 /// \brief Set element \f$i\f$ to the \e zero value
|
Chris@101
|
1040 /// \param i index of the element
|
Chris@101
|
1041 BOOST_UBLAS_INLINE
|
Chris@101
|
1042 void erase_element (size_type i) {
|
Chris@101
|
1043 BOOST_UBLAS_CHECK (i < data_.size(), bad_index ());
|
Chris@101
|
1044 data () [i] = value_type/*zero*/();
|
Chris@101
|
1045 }
|
Chris@101
|
1046
|
Chris@101
|
1047 // -------
|
Chris@101
|
1048 // Zeroing
|
Chris@101
|
1049 // -------
|
Chris@101
|
1050
|
Chris@101
|
1051 /// \brief Clear the vector, i.e. set all values to the \c zero value.
|
Chris@101
|
1052 BOOST_UBLAS_INLINE
|
Chris@101
|
1053 void clear () {
|
Chris@101
|
1054 std::fill (data ().begin (), data ().end (), value_type/*zero*/());
|
Chris@101
|
1055 }
|
Chris@101
|
1056
|
Chris@101
|
1057 // Assignment
|
Chris@101
|
1058 #ifdef BOOST_UBLAS_MOVE_SEMANTICS
|
Chris@101
|
1059
|
Chris@101
|
1060 /// \brief Assign a full fixed_vector (\e RHS-vector) to the current fixed_vector (\e LHS-vector)
|
Chris@101
|
1061 /// \param v is the source vector
|
Chris@101
|
1062 /// \return a reference to a fixed_vector (i.e. the destination vector)
|
Chris@101
|
1063 /*! @note "pass by value" the key idea to enable move semantics */
|
Chris@101
|
1064 BOOST_UBLAS_INLINE
|
Chris@101
|
1065 fixed_vector &operator = (fixed_vector v) {
|
Chris@101
|
1066 assign_temporary(v);
|
Chris@101
|
1067 return *this;
|
Chris@101
|
1068 }
|
Chris@101
|
1069 #else
|
Chris@101
|
1070 /// \brief Assign a full fixed_vector (\e RHS-vector) to the current fixed_vector (\e LHS-vector)
|
Chris@101
|
1071 /// \param v is the source fixed_vector
|
Chris@101
|
1072 /// \return a reference to a fixed_vector (i.e. the destination vector)
|
Chris@101
|
1073 BOOST_UBLAS_INLINE
|
Chris@101
|
1074 fixed_vector &operator = (const fixed_vector &v) {
|
Chris@101
|
1075 data () = v.data ();
|
Chris@101
|
1076 return *this;
|
Chris@101
|
1077 }
|
Chris@101
|
1078 #endif
|
Chris@101
|
1079
|
Chris@101
|
1080 /// \brief Assign a full vector (\e RHS-vector) to the current fixed_vector (\e LHS-vector)
|
Chris@101
|
1081 /// Assign a full vector (\e RHS-vector) to the current fixed_vector (\e LHS-vector). This method does not create any temporary.
|
Chris@101
|
1082 /// \param v is the source vector container
|
Chris@101
|
1083 /// \return a reference to a vector (i.e. the destination vector)
|
Chris@101
|
1084 template<class C> // Container assignment without temporary
|
Chris@101
|
1085 BOOST_UBLAS_INLINE
|
Chris@101
|
1086 fixed_vector &operator = (const vector_container<C> &v) {
|
Chris@101
|
1087 assign (v);
|
Chris@101
|
1088 return *this;
|
Chris@101
|
1089 }
|
Chris@101
|
1090
|
Chris@101
|
1091 /// \brief Assign a full fixed_vector (\e RHS-vector) to the current fixed_vector (\e LHS-vector)
|
Chris@101
|
1092 /// \param v is the source fixed_vector
|
Chris@101
|
1093 /// \return a reference to a fixed_vector (i.e. the destination fixed_vector)
|
Chris@101
|
1094 BOOST_UBLAS_INLINE
|
Chris@101
|
1095 fixed_vector &assign_temporary (fixed_vector &v) {
|
Chris@101
|
1096 swap ( v );
|
Chris@101
|
1097 return *this;
|
Chris@101
|
1098 }
|
Chris@101
|
1099
|
Chris@101
|
1100 /// \brief Assign the result of a vector_expression to the fixed_vector
|
Chris@101
|
1101 /// Assign the result of a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1102 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1103 /// \param ae is a const reference to the vector_expression
|
Chris@101
|
1104 /// \return a reference to the resulting fixed_vector
|
Chris@101
|
1105 template<class AE>
|
Chris@101
|
1106 BOOST_UBLAS_INLINE
|
Chris@101
|
1107 fixed_vector &operator = (const vector_expression<AE> &ae) {
|
Chris@101
|
1108 self_type temporary (ae);
|
Chris@101
|
1109 return assign_temporary (temporary);
|
Chris@101
|
1110 }
|
Chris@101
|
1111
|
Chris@101
|
1112 /// \brief Assign the result of a vector_expression to the fixed_vector
|
Chris@101
|
1113 /// Assign the result of a vector_expression to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1114 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1115 /// \param ae is a const reference to the vector_expression
|
Chris@101
|
1116 /// \return a reference to the resulting fixed_vector
|
Chris@101
|
1117 template<class AE>
|
Chris@101
|
1118 BOOST_UBLAS_INLINE
|
Chris@101
|
1119 fixed_vector &assign (const vector_expression<AE> &ae) {
|
Chris@101
|
1120 vector_assign<scalar_assign> (*this, ae);
|
Chris@101
|
1121 return *this;
|
Chris@101
|
1122 }
|
Chris@101
|
1123
|
Chris@101
|
1124 // -------------------
|
Chris@101
|
1125 // Computed assignment
|
Chris@101
|
1126 // -------------------
|
Chris@101
|
1127
|
Chris@101
|
1128 /// \brief Assign the sum of the fixed_vector and a vector_expression to the fixed_vector
|
Chris@101
|
1129 /// Assign the sum of the fixed_vector and a vector_expression to the fixed_vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1130 /// A temporary is created for the computations.
|
Chris@101
|
1131 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1132 /// \param ae is a const reference to the vector_expression
|
Chris@101
|
1133 /// \return a reference to the resulting fixed_vector
|
Chris@101
|
1134 template<class AE>
|
Chris@101
|
1135 BOOST_UBLAS_INLINE
|
Chris@101
|
1136 fixed_vector &operator += (const vector_expression<AE> &ae) {
|
Chris@101
|
1137 self_type temporary (*this + ae);
|
Chris@101
|
1138 return assign_temporary (temporary);
|
Chris@101
|
1139 }
|
Chris@101
|
1140
|
Chris@101
|
1141 /// \brief Assign the sum of the fixed_vector and a vector_expression to the fixed_vector
|
Chris@101
|
1142 /// Assign the sum of the fixed_vector and a vector_expression to the fixed_vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1143 /// No temporary is created. Computations are done and stored directly into the resulting vector.
|
Chris@101
|
1144 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1145 /// \param ae is a const reference to the vector_expression
|
Chris@101
|
1146 /// \return a reference to the resulting vector
|
Chris@101
|
1147 template<class C> // Container assignment without temporary
|
Chris@101
|
1148 BOOST_UBLAS_INLINE
|
Chris@101
|
1149 fixed_vector &operator += (const vector_container<C> &v) {
|
Chris@101
|
1150 plus_assign (v);
|
Chris@101
|
1151 return *this;
|
Chris@101
|
1152 }
|
Chris@101
|
1153
|
Chris@101
|
1154 /// \brief Assign the sum of the fixed_vector and a vector_expression to the fixed_vector
|
Chris@101
|
1155 /// Assign the sum of the fixed_vector and a vector_expression to the fixed_vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1156 /// No temporary is created. Computations are done and stored directly into the resulting fixed_vector.
|
Chris@101
|
1157 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1158 /// \param ae is a const reference to the vector_expression
|
Chris@101
|
1159 /// \return a reference to the resulting vector
|
Chris@101
|
1160 template<class AE>
|
Chris@101
|
1161 BOOST_UBLAS_INLINE
|
Chris@101
|
1162 fixed_vector &plus_assign (const vector_expression<AE> &ae) {
|
Chris@101
|
1163 vector_assign<scalar_plus_assign> (*this, ae);
|
Chris@101
|
1164 return *this;
|
Chris@101
|
1165 }
|
Chris@101
|
1166
|
Chris@101
|
1167 /// \brief Assign the difference of the fixed_vector and a vector_expression to the fixed_vector
|
Chris@101
|
1168 /// Assign the difference of the fixed_vector and a vector_expression to the fixed_vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1169 /// A temporary is created for the computations.
|
Chris@101
|
1170 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1171 /// \param ae is a const reference to the vector_expression
|
Chris@101
|
1172 template<class AE>
|
Chris@101
|
1173 BOOST_UBLAS_INLINE
|
Chris@101
|
1174 fixed_vector &operator -= (const vector_expression<AE> &ae) {
|
Chris@101
|
1175 self_type temporary (*this - ae);
|
Chris@101
|
1176 return assign_temporary (temporary);
|
Chris@101
|
1177 }
|
Chris@101
|
1178
|
Chris@101
|
1179 /// \brief Assign the difference of the fixed_vector and a vector_expression to the fixed_vector
|
Chris@101
|
1180 /// Assign the difference of the fixed_vector and a vector_expression to the fixed_vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1181 /// No temporary is created. Computations are done and stored directly into the resulting fixed_vector.
|
Chris@101
|
1182 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1183 /// \param ae is a const reference to the vector_expression
|
Chris@101
|
1184 /// \return a reference to the resulting vector
|
Chris@101
|
1185 template<class C> // Container assignment without temporary
|
Chris@101
|
1186 BOOST_UBLAS_INLINE
|
Chris@101
|
1187 fixed_vector &operator -= (const vector_container<C> &v) {
|
Chris@101
|
1188 minus_assign (v);
|
Chris@101
|
1189 return *this;
|
Chris@101
|
1190 }
|
Chris@101
|
1191
|
Chris@101
|
1192 /// \brief Assign the difference of the fixed_vector and a vector_expression to the fixed_vector
|
Chris@101
|
1193 /// Assign the difference of the fixed_vector and a vector_expression to the fixed_vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1194 /// No temporary is created. Computations are done and stored directly into the resulting fixed_vector.
|
Chris@101
|
1195 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1196 /// \param ae is a const reference to the vector_expression
|
Chris@101
|
1197 /// \return a reference to the resulting fixed_vector
|
Chris@101
|
1198 template<class AE>
|
Chris@101
|
1199 BOOST_UBLAS_INLINE
|
Chris@101
|
1200 fixed_vector &minus_assign (const vector_expression<AE> &ae) {
|
Chris@101
|
1201 vector_assign<scalar_minus_assign> (*this, ae);
|
Chris@101
|
1202 return *this;
|
Chris@101
|
1203 }
|
Chris@101
|
1204
|
Chris@101
|
1205 /// \brief Assign the product of the fixed_vector and a scalar to the fixed_vector
|
Chris@101
|
1206 /// Assign the product of the fixed_vector and a scalar to the fixed_vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1207 /// No temporary is created. Computations are done and stored directly into the resulting fixed_vector.
|
Chris@101
|
1208 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1209 /// \param at is a const reference to the scalar
|
Chris@101
|
1210 /// \return a reference to the resulting fixed_vector
|
Chris@101
|
1211 template<class AT>
|
Chris@101
|
1212 BOOST_UBLAS_INLINE
|
Chris@101
|
1213 fixed_vector &operator *= (const AT &at) {
|
Chris@101
|
1214 vector_assign_scalar<scalar_multiplies_assign> (*this, at);
|
Chris@101
|
1215 return *this;
|
Chris@101
|
1216 }
|
Chris@101
|
1217
|
Chris@101
|
1218 /// \brief Assign the division of the fixed_vector by a scalar to the fixed_vector
|
Chris@101
|
1219 /// Assign the division of the fixed_vector by a scalar to the vector. This is lazy-compiled and will be optimized out by the compiler on any type of expression.
|
Chris@101
|
1220 /// No temporary is created. Computations are done and stored directly into the resulting vector.
|
Chris@101
|
1221 /// \tparam AE is the type of the vector_expression
|
Chris@101
|
1222 /// \param at is a const reference to the scalar
|
Chris@101
|
1223 /// \return a reference to the resulting fixed_vector
|
Chris@101
|
1224 template<class AT>
|
Chris@101
|
1225 BOOST_UBLAS_INLINE
|
Chris@101
|
1226 fixed_vector &operator /= (const AT &at) {
|
Chris@101
|
1227 vector_assign_scalar<scalar_divides_assign> (*this, at);
|
Chris@101
|
1228 return *this;
|
Chris@101
|
1229 }
|
Chris@101
|
1230
|
Chris@101
|
1231 // --------
|
Chris@101
|
1232 // Swapping
|
Chris@101
|
1233 // --------
|
Chris@101
|
1234
|
Chris@101
|
1235 /// \brief Swap the content of the fixed_vector with another vector
|
Chris@101
|
1236 /// \param v is the fixed_vector to be swapped with
|
Chris@101
|
1237 BOOST_UBLAS_INLINE
|
Chris@101
|
1238 void swap (fixed_vector &v) {
|
Chris@101
|
1239 if (this != &v) {
|
Chris@101
|
1240 data ().swap (v.data ());
|
Chris@101
|
1241 }
|
Chris@101
|
1242 }
|
Chris@101
|
1243
|
Chris@101
|
1244 /// \brief Swap the content of two fixed_vectors
|
Chris@101
|
1245 /// \param v1 is the first fixed_vector. It takes values from v2
|
Chris@101
|
1246 /// \param v2 is the second fixed_vector It takes values from v1
|
Chris@101
|
1247 BOOST_UBLAS_INLINE
|
Chris@101
|
1248 friend void swap (fixed_vector &v1, fixed_vector &v2) {
|
Chris@101
|
1249 v1.swap (v2);
|
Chris@101
|
1250 }
|
Chris@101
|
1251
|
Chris@101
|
1252 // Iterator types
|
Chris@101
|
1253 private:
|
Chris@101
|
1254 // Use the storage array iterator
|
Chris@101
|
1255 typedef typename A::const_iterator const_subiterator_type;
|
Chris@101
|
1256 typedef typename A::iterator subiterator_type;
|
Chris@101
|
1257
|
Chris@101
|
1258 public:
|
Chris@101
|
1259 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@101
|
1260 typedef indexed_iterator<self_type, dense_random_access_iterator_tag> iterator;
|
Chris@101
|
1261 typedef indexed_const_iterator<self_type, dense_random_access_iterator_tag> const_iterator;
|
Chris@101
|
1262 #else
|
Chris@101
|
1263 class const_iterator;
|
Chris@101
|
1264 class iterator;
|
Chris@101
|
1265 #endif
|
Chris@101
|
1266
|
Chris@101
|
1267 // --------------
|
Chris@101
|
1268 // Element lookup
|
Chris@101
|
1269 // --------------
|
Chris@101
|
1270
|
Chris@101
|
1271 /// \brief Return a const iterator to the element \e i
|
Chris@101
|
1272 /// \param i index of the element
|
Chris@101
|
1273 BOOST_UBLAS_INLINE
|
Chris@101
|
1274 const_iterator find (size_type i) const {
|
Chris@101
|
1275 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@101
|
1276 return const_iterator (*this, data ().begin () + i);
|
Chris@101
|
1277 #else
|
Chris@101
|
1278 return const_iterator (*this, i);
|
Chris@101
|
1279 #endif
|
Chris@101
|
1280 }
|
Chris@101
|
1281
|
Chris@101
|
1282 /// \brief Return an iterator to the element \e i
|
Chris@101
|
1283 /// \param i index of the element
|
Chris@101
|
1284 BOOST_UBLAS_INLINE
|
Chris@101
|
1285 iterator find (size_type i) {
|
Chris@101
|
1286 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@101
|
1287 return iterator (*this, data ().begin () + i);
|
Chris@101
|
1288 #else
|
Chris@101
|
1289 return iterator (*this, i);
|
Chris@101
|
1290 #endif
|
Chris@101
|
1291 }
|
Chris@101
|
1292
|
Chris@101
|
1293 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@101
|
1294 class const_iterator:
|
Chris@101
|
1295 public container_const_reference<fixed_vector>,
|
Chris@101
|
1296 public random_access_iterator_base<dense_random_access_iterator_tag,
|
Chris@101
|
1297 const_iterator, value_type, difference_type> {
|
Chris@101
|
1298 public:
|
Chris@101
|
1299 typedef typename fixed_vector::difference_type difference_type;
|
Chris@101
|
1300 typedef typename fixed_vector::value_type value_type;
|
Chris@101
|
1301 typedef typename fixed_vector::const_reference reference;
|
Chris@101
|
1302 typedef const typename fixed_vector::pointer pointer;
|
Chris@101
|
1303
|
Chris@101
|
1304 // ----------------------------
|
Chris@101
|
1305 // Construction and destruction
|
Chris@101
|
1306 // ----------------------------
|
Chris@101
|
1307
|
Chris@101
|
1308
|
Chris@101
|
1309 BOOST_UBLAS_INLINE
|
Chris@101
|
1310 const_iterator ():
|
Chris@101
|
1311 container_const_reference<self_type> (), it_ () {}
|
Chris@101
|
1312 BOOST_UBLAS_INLINE
|
Chris@101
|
1313 const_iterator (const self_type &v, const const_subiterator_type &it):
|
Chris@101
|
1314 container_const_reference<self_type> (v), it_ (it) {}
|
Chris@101
|
1315 BOOST_UBLAS_INLINE
|
Chris@101
|
1316 const_iterator (const typename self_type::iterator &it): // ISSUE vector:: stops VC8 using std::iterator here
|
Chris@101
|
1317 container_const_reference<self_type> (it ()), it_ (it.it_) {}
|
Chris@101
|
1318
|
Chris@101
|
1319 // ----------
|
Chris@101
|
1320 // Arithmetic
|
Chris@101
|
1321 // ----------
|
Chris@101
|
1322
|
Chris@101
|
1323 /// \brief Increment by 1 the position of the iterator
|
Chris@101
|
1324 /// \return a reference to the const iterator
|
Chris@101
|
1325 BOOST_UBLAS_INLINE
|
Chris@101
|
1326 const_iterator &operator ++ () {
|
Chris@101
|
1327 ++ it_;
|
Chris@101
|
1328 return *this;
|
Chris@101
|
1329 }
|
Chris@101
|
1330
|
Chris@101
|
1331 /// \brief Decrement by 1 the position of the iterator
|
Chris@101
|
1332 /// \return a reference to the const iterator
|
Chris@101
|
1333 BOOST_UBLAS_INLINE
|
Chris@101
|
1334 const_iterator &operator -- () {
|
Chris@101
|
1335 -- it_;
|
Chris@101
|
1336 return *this;
|
Chris@101
|
1337 }
|
Chris@101
|
1338
|
Chris@101
|
1339 /// \brief Increment by \e n the position of the iterator
|
Chris@101
|
1340 /// \return a reference to the const iterator
|
Chris@101
|
1341 BOOST_UBLAS_INLINE
|
Chris@101
|
1342 const_iterator &operator += (difference_type n) {
|
Chris@101
|
1343 it_ += n;
|
Chris@101
|
1344 return *this;
|
Chris@101
|
1345 }
|
Chris@101
|
1346
|
Chris@101
|
1347 /// \brief Decrement by \e n the position of the iterator
|
Chris@101
|
1348 /// \return a reference to the const iterator
|
Chris@101
|
1349 BOOST_UBLAS_INLINE
|
Chris@101
|
1350 const_iterator &operator -= (difference_type n) {
|
Chris@101
|
1351 it_ -= n;
|
Chris@101
|
1352 return *this;
|
Chris@101
|
1353 }
|
Chris@101
|
1354
|
Chris@101
|
1355 /// \brief Return the different in number of positions between 2 iterators
|
Chris@101
|
1356 BOOST_UBLAS_INLINE
|
Chris@101
|
1357 difference_type operator - (const const_iterator &it) const {
|
Chris@101
|
1358 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@101
|
1359 return it_ - it.it_;
|
Chris@101
|
1360 }
|
Chris@101
|
1361
|
Chris@101
|
1362 /// \brief Dereference an iterator
|
Chris@101
|
1363 /// Dereference an iterator: a bounds' check is done before returning the value. A bad_index() expection is returned if out of bounds.
|
Chris@101
|
1364 /// \return a const reference to the value pointed by the iterator
|
Chris@101
|
1365 BOOST_UBLAS_INLINE
|
Chris@101
|
1366 const_reference operator * () const {
|
Chris@101
|
1367 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
|
Chris@101
|
1368 return *it_;
|
Chris@101
|
1369 }
|
Chris@101
|
1370
|
Chris@101
|
1371 /// \brief Dereference an iterator at the n-th forward value
|
Chris@101
|
1372 /// Dereference an iterator at the n-th forward value, that is the value pointed by iterator+n.
|
Chris@101
|
1373 /// A bounds' check is done before returning the value. A bad_index() expection is returned if out of bounds.
|
Chris@101
|
1374 /// \return a const reference
|
Chris@101
|
1375 BOOST_UBLAS_INLINE
|
Chris@101
|
1376 const_reference operator [] (difference_type n) const {
|
Chris@101
|
1377 return *(it_ + n);
|
Chris@101
|
1378 }
|
Chris@101
|
1379
|
Chris@101
|
1380 // Index
|
Chris@101
|
1381 /// \brief return the index of the element referenced by the iterator
|
Chris@101
|
1382 BOOST_UBLAS_INLINE
|
Chris@101
|
1383 size_type index () const {
|
Chris@101
|
1384 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
|
Chris@101
|
1385 return it_ - (*this) ().begin ().it_;
|
Chris@101
|
1386 }
|
Chris@101
|
1387
|
Chris@101
|
1388 // Assignment
|
Chris@101
|
1389 BOOST_UBLAS_INLINE
|
Chris@101
|
1390 /// \brief assign the value of an iterator to the iterator
|
Chris@101
|
1391 const_iterator &operator = (const const_iterator &it) {
|
Chris@101
|
1392 container_const_reference<self_type>::assign (&it ());
|
Chris@101
|
1393 it_ = it.it_;
|
Chris@101
|
1394 return *this;
|
Chris@101
|
1395 }
|
Chris@101
|
1396
|
Chris@101
|
1397 // Comparison
|
Chris@101
|
1398 /// \brief compare the value of two itetarors
|
Chris@101
|
1399 /// \return true if they reference the same element
|
Chris@101
|
1400 BOOST_UBLAS_INLINE
|
Chris@101
|
1401 bool operator == (const const_iterator &it) const {
|
Chris@101
|
1402 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@101
|
1403 return it_ == it.it_;
|
Chris@101
|
1404 }
|
Chris@101
|
1405
|
Chris@101
|
1406
|
Chris@101
|
1407 /// \brief compare the value of two iterators
|
Chris@101
|
1408 /// \return return true if the left-hand-side iterator refers to a value placed before the right-hand-side iterator
|
Chris@101
|
1409 BOOST_UBLAS_INLINE
|
Chris@101
|
1410 bool operator < (const const_iterator &it) const {
|
Chris@101
|
1411 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@101
|
1412 return it_ < it.it_;
|
Chris@101
|
1413 }
|
Chris@101
|
1414
|
Chris@101
|
1415 private:
|
Chris@101
|
1416 const_subiterator_type it_;
|
Chris@101
|
1417
|
Chris@101
|
1418 friend class iterator;
|
Chris@101
|
1419 };
|
Chris@101
|
1420 #endif
|
Chris@101
|
1421
|
Chris@101
|
1422 /// \brief return an iterator on the first element of the fixed_vector
|
Chris@101
|
1423 BOOST_UBLAS_INLINE
|
Chris@101
|
1424 const_iterator begin () const {
|
Chris@101
|
1425 return find (0);
|
Chris@101
|
1426 }
|
Chris@101
|
1427
|
Chris@101
|
1428 /// \brief return an iterator on the first element of the fixed_vector
|
Chris@101
|
1429 BOOST_UBLAS_INLINE
|
Chris@101
|
1430 const_iterator cbegin () const {
|
Chris@101
|
1431 return begin ();
|
Chris@101
|
1432 }
|
Chris@101
|
1433
|
Chris@101
|
1434 /// \brief return an iterator after the last element of the fixed_vector
|
Chris@101
|
1435 BOOST_UBLAS_INLINE
|
Chris@101
|
1436 const_iterator end () const {
|
Chris@101
|
1437 return find (data_.size ());
|
Chris@101
|
1438 }
|
Chris@101
|
1439
|
Chris@101
|
1440 /// \brief return an iterator after the last element of the fixed_vector
|
Chris@101
|
1441 BOOST_UBLAS_INLINE
|
Chris@101
|
1442 const_iterator cend () const {
|
Chris@101
|
1443 return end ();
|
Chris@101
|
1444 }
|
Chris@101
|
1445
|
Chris@101
|
1446 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@101
|
1447 class iterator:
|
Chris@101
|
1448 public container_reference<fixed_vector>,
|
Chris@101
|
1449 public random_access_iterator_base<dense_random_access_iterator_tag,
|
Chris@101
|
1450 iterator, value_type, difference_type> {
|
Chris@101
|
1451 public:
|
Chris@101
|
1452 typedef typename fixed_vector::difference_type difference_type;
|
Chris@101
|
1453 typedef typename fixed_vector::value_type value_type;
|
Chris@101
|
1454 typedef typename fixed_vector::reference reference;
|
Chris@101
|
1455 typedef typename fixed_vector::pointer pointer;
|
Chris@101
|
1456
|
Chris@101
|
1457
|
Chris@101
|
1458 // Construction and destruction
|
Chris@101
|
1459 BOOST_UBLAS_INLINE
|
Chris@101
|
1460 iterator ():
|
Chris@101
|
1461 container_reference<self_type> (), it_ () {}
|
Chris@101
|
1462 BOOST_UBLAS_INLINE
|
Chris@101
|
1463 iterator (self_type &v, const subiterator_type &it):
|
Chris@101
|
1464 container_reference<self_type> (v), it_ (it) {}
|
Chris@101
|
1465
|
Chris@101
|
1466 // Arithmetic
|
Chris@101
|
1467 BOOST_UBLAS_INLINE
|
Chris@101
|
1468 iterator &operator ++ () {
|
Chris@101
|
1469 ++ it_;
|
Chris@101
|
1470 return *this;
|
Chris@101
|
1471 }
|
Chris@101
|
1472 BOOST_UBLAS_INLINE
|
Chris@101
|
1473 iterator &operator -- () {
|
Chris@101
|
1474 -- it_;
|
Chris@101
|
1475 return *this;
|
Chris@101
|
1476 }
|
Chris@101
|
1477 BOOST_UBLAS_INLINE
|
Chris@101
|
1478 iterator &operator += (difference_type n) {
|
Chris@101
|
1479 it_ += n;
|
Chris@101
|
1480 return *this;
|
Chris@101
|
1481 }
|
Chris@101
|
1482 BOOST_UBLAS_INLINE
|
Chris@101
|
1483 iterator &operator -= (difference_type n) {
|
Chris@101
|
1484 it_ -= n;
|
Chris@101
|
1485 return *this;
|
Chris@101
|
1486 }
|
Chris@101
|
1487 BOOST_UBLAS_INLINE
|
Chris@101
|
1488 difference_type operator - (const iterator &it) const {
|
Chris@101
|
1489 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@101
|
1490 return it_ - it.it_;
|
Chris@101
|
1491 }
|
Chris@101
|
1492
|
Chris@101
|
1493 // Dereference
|
Chris@101
|
1494 BOOST_UBLAS_INLINE
|
Chris@101
|
1495 reference operator * () const {
|
Chris@101
|
1496 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_ , bad_index ());
|
Chris@101
|
1497 return *it_;
|
Chris@101
|
1498 }
|
Chris@101
|
1499 BOOST_UBLAS_INLINE
|
Chris@101
|
1500 reference operator [] (difference_type n) const {
|
Chris@101
|
1501 return *(it_ + n);
|
Chris@101
|
1502 }
|
Chris@101
|
1503
|
Chris@101
|
1504 // Index
|
Chris@101
|
1505 BOOST_UBLAS_INLINE
|
Chris@101
|
1506 size_type index () const {
|
Chris@101
|
1507 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_ , bad_index ());
|
Chris@101
|
1508 return it_ - (*this) ().begin ().it_;
|
Chris@101
|
1509 }
|
Chris@101
|
1510
|
Chris@101
|
1511 // Assignment
|
Chris@101
|
1512 BOOST_UBLAS_INLINE
|
Chris@101
|
1513 iterator &operator = (const iterator &it) {
|
Chris@101
|
1514 container_reference<self_type>::assign (&it ());
|
Chris@101
|
1515 it_ = it.it_;
|
Chris@101
|
1516 return *this;
|
Chris@101
|
1517 }
|
Chris@101
|
1518
|
Chris@101
|
1519 // Comparison
|
Chris@101
|
1520 BOOST_UBLAS_INLINE
|
Chris@101
|
1521 bool operator == (const iterator &it) const {
|
Chris@101
|
1522 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@101
|
1523 return it_ == it.it_;
|
Chris@101
|
1524 }
|
Chris@101
|
1525 BOOST_UBLAS_INLINE
|
Chris@101
|
1526 bool operator < (const iterator &it) const {
|
Chris@101
|
1527 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@101
|
1528 return it_ < it.it_;
|
Chris@101
|
1529 }
|
Chris@101
|
1530
|
Chris@101
|
1531 private:
|
Chris@101
|
1532 subiterator_type it_;
|
Chris@101
|
1533
|
Chris@101
|
1534 friend class const_iterator;
|
Chris@101
|
1535 };
|
Chris@101
|
1536 #endif
|
Chris@101
|
1537
|
Chris@101
|
1538 /// \brief Return an iterator on the first element of the fixed_vector
|
Chris@101
|
1539 BOOST_UBLAS_INLINE
|
Chris@101
|
1540 iterator begin () {
|
Chris@101
|
1541 return find (0);
|
Chris@101
|
1542 }
|
Chris@101
|
1543
|
Chris@101
|
1544 /// \brief Return an iterator at the end of the fixed_vector
|
Chris@101
|
1545 BOOST_UBLAS_INLINE
|
Chris@101
|
1546 iterator end () {
|
Chris@101
|
1547 return find (data_.size ());
|
Chris@101
|
1548 }
|
Chris@101
|
1549
|
Chris@101
|
1550 // Reverse iterator
|
Chris@101
|
1551 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
|
Chris@101
|
1552 typedef reverse_iterator_base<iterator> reverse_iterator;
|
Chris@101
|
1553
|
Chris@101
|
1554 /// \brief Return a const reverse iterator before the first element of the reversed fixed_vector (i.e. end() of normal fixed_vector)
|
Chris@101
|
1555 BOOST_UBLAS_INLINE
|
Chris@101
|
1556 const_reverse_iterator rbegin () const {
|
Chris@101
|
1557 return const_reverse_iterator (end ());
|
Chris@101
|
1558 }
|
Chris@101
|
1559
|
Chris@101
|
1560 /// \brief Return a const reverse iterator before the first element of the reversed fixed_vector (i.e. end() of normal fixed_vector)
|
Chris@101
|
1561 BOOST_UBLAS_INLINE
|
Chris@101
|
1562 const_reverse_iterator crbegin () const {
|
Chris@101
|
1563 return rbegin ();
|
Chris@101
|
1564 }
|
Chris@101
|
1565
|
Chris@101
|
1566 /// \brief Return a const reverse iterator on the end of the reverse fixed_vector (i.e. first element of the normal fixed_vector)
|
Chris@101
|
1567 BOOST_UBLAS_INLINE
|
Chris@101
|
1568 const_reverse_iterator rend () const {
|
Chris@101
|
1569 return const_reverse_iterator (begin ());
|
Chris@101
|
1570 }
|
Chris@101
|
1571
|
Chris@101
|
1572 /// \brief Return a const reverse iterator on the end of the reverse fixed_vector (i.e. first element of the normal fixed_vector)
|
Chris@101
|
1573 BOOST_UBLAS_INLINE
|
Chris@101
|
1574 const_reverse_iterator crend () const {
|
Chris@101
|
1575 return rend ();
|
Chris@101
|
1576 }
|
Chris@101
|
1577
|
Chris@101
|
1578 /// \brief Return a const reverse iterator before the first element of the reversed fixed_vector (i.e. end() of normal fixed_vector)
|
Chris@101
|
1579 BOOST_UBLAS_INLINE
|
Chris@101
|
1580 reverse_iterator rbegin () {
|
Chris@101
|
1581 return reverse_iterator (end ());
|
Chris@101
|
1582 }
|
Chris@101
|
1583
|
Chris@101
|
1584 /// \brief Return a const reverse iterator on the end of the reverse fixed_vector (i.e. first element of the normal fixed_vector)
|
Chris@101
|
1585 BOOST_UBLAS_INLINE
|
Chris@101
|
1586 reverse_iterator rend () {
|
Chris@101
|
1587 return reverse_iterator (begin ());
|
Chris@101
|
1588 }
|
Chris@101
|
1589
|
Chris@101
|
1590 // -------------
|
Chris@101
|
1591 // Serialization
|
Chris@101
|
1592 // -------------
|
Chris@101
|
1593
|
Chris@101
|
1594 /// Serialize a fixed_vector into and archive as defined in Boost
|
Chris@101
|
1595 /// \param ar Archive object. Can be a flat file, an XML file or any other stream
|
Chris@101
|
1596 /// \param file_version Optional file version (not yet used)
|
Chris@101
|
1597 template<class Archive>
|
Chris@101
|
1598 void serialize(Archive & ar, const unsigned int /* file_version */){
|
Chris@101
|
1599 ar & serialization::make_nvp("data",data_);
|
Chris@101
|
1600 }
|
Chris@101
|
1601
|
Chris@101
|
1602 private:
|
Chris@101
|
1603 array_type data_;
|
Chris@101
|
1604 };
|
Chris@101
|
1605
|
Chris@101
|
1606 #endif // BOOST_UBLAS_CPP_GE_2011
|
Chris@101
|
1607
|
Chris@16
|
1608 // --------------------
|
Chris@16
|
1609 // Bounded vector class
|
Chris@16
|
1610 // --------------------
|
Chris@16
|
1611
|
Chris@16
|
1612 /// \brief a dense vector of values of type \c T, of variable size but with maximum \f$N\f$.
|
Chris@16
|
1613 /// A dense vector of values of type \c T, of variable size but with maximum \f$N\f$. The default constructor
|
Chris@16
|
1614 /// creates the vector with size \f$N\f$. Elements are constructed by the storage type \c bounded_array, which \b need \b not \b initialise their value.
|
Chris@16
|
1615 template<class T, std::size_t N>
|
Chris@16
|
1616 class bounded_vector:
|
Chris@16
|
1617 public vector<T, bounded_array<T, N> > {
|
Chris@16
|
1618
|
Chris@16
|
1619 typedef vector<T, bounded_array<T, N> > vector_type;
|
Chris@16
|
1620 public:
|
Chris@16
|
1621 typedef typename vector_type::size_type size_type;
|
Chris@16
|
1622 static const size_type max_size = N;
|
Chris@16
|
1623
|
Chris@16
|
1624 // Construction and destruction
|
Chris@16
|
1625 BOOST_UBLAS_INLINE
|
Chris@16
|
1626 bounded_vector ():
|
Chris@16
|
1627 vector_type (N) {}
|
Chris@16
|
1628 BOOST_UBLAS_INLINE
|
Chris@16
|
1629 bounded_vector (size_type size):
|
Chris@16
|
1630 vector_type (size) {}
|
Chris@16
|
1631 BOOST_UBLAS_INLINE
|
Chris@16
|
1632 bounded_vector (const bounded_vector &v):
|
Chris@16
|
1633 vector_type (v) {}
|
Chris@16
|
1634 template<class A2> // Allow vector<T,bounded_array<N> construction
|
Chris@16
|
1635 BOOST_UBLAS_INLINE
|
Chris@16
|
1636 bounded_vector (const vector<T, A2> &v):
|
Chris@16
|
1637 vector_type (v) {}
|
Chris@16
|
1638 template<class AE>
|
Chris@16
|
1639 BOOST_UBLAS_INLINE
|
Chris@16
|
1640 bounded_vector (const vector_expression<AE> &ae):
|
Chris@16
|
1641 vector_type (ae) {}
|
Chris@16
|
1642 BOOST_UBLAS_INLINE
|
Chris@16
|
1643 ~bounded_vector () {}
|
Chris@16
|
1644
|
Chris@16
|
1645 // Assignment
|
Chris@16
|
1646 #ifdef BOOST_UBLAS_MOVE_SEMANTICS
|
Chris@16
|
1647
|
Chris@16
|
1648 /*! @note "pass by value" the key idea to enable move semantics */
|
Chris@16
|
1649 BOOST_UBLAS_INLINE
|
Chris@16
|
1650 bounded_vector &operator = (bounded_vector v) {
|
Chris@16
|
1651 vector_type::operator = (v);
|
Chris@16
|
1652 return *this;
|
Chris@16
|
1653 }
|
Chris@16
|
1654 #else
|
Chris@16
|
1655 BOOST_UBLAS_INLINE
|
Chris@16
|
1656 bounded_vector &operator = (const bounded_vector &v) {
|
Chris@16
|
1657 vector_type::operator = (v);
|
Chris@16
|
1658 return *this;
|
Chris@16
|
1659 }
|
Chris@16
|
1660 #endif
|
Chris@16
|
1661 template<class A2> // Generic vector assignment
|
Chris@16
|
1662 BOOST_UBLAS_INLINE
|
Chris@16
|
1663 bounded_vector &operator = (const vector<T, A2> &v) {
|
Chris@16
|
1664 vector_type::operator = (v);
|
Chris@16
|
1665 return *this;
|
Chris@16
|
1666 }
|
Chris@16
|
1667 template<class C> // Container assignment without temporary
|
Chris@16
|
1668 BOOST_UBLAS_INLINE
|
Chris@16
|
1669 bounded_vector &operator = (const vector_container<C> &v) {
|
Chris@16
|
1670 vector_type::operator = (v);
|
Chris@16
|
1671 return *this;
|
Chris@16
|
1672 }
|
Chris@16
|
1673 template<class AE>
|
Chris@16
|
1674 BOOST_UBLAS_INLINE
|
Chris@16
|
1675 bounded_vector &operator = (const vector_expression<AE> &ae) {
|
Chris@16
|
1676 vector_type::operator = (ae);
|
Chris@16
|
1677 return *this;
|
Chris@16
|
1678 }
|
Chris@16
|
1679 };
|
Chris@16
|
1680
|
Chris@16
|
1681
|
Chris@101
|
1682
|
Chris@16
|
1683 // -----------------
|
Chris@16
|
1684 // Zero vector class
|
Chris@16
|
1685 // -----------------
|
Chris@16
|
1686
|
Chris@16
|
1687 /// \brief A zero vector of type \c T and a given \c size
|
Chris@16
|
1688 /// A zero vector of type \c T and a given \c size. This is a virtual vector in the sense that no memory is allocated
|
Chris@16
|
1689 /// for storing the zero values: it still acts like any other vector. However assigning values to it will not change the zero
|
Chris@16
|
1690 /// vector into a normal vector. It must first be assigned to another normal vector by any suitable means. Its memory footprint is constant.
|
Chris@16
|
1691 template<class T, class ALLOC>
|
Chris@16
|
1692 class zero_vector:
|
Chris@16
|
1693 public vector_container<zero_vector<T, ALLOC> > {
|
Chris@16
|
1694
|
Chris@16
|
1695 typedef const T *const_pointer;
|
Chris@16
|
1696 typedef zero_vector<T, ALLOC> self_type;
|
Chris@16
|
1697 public:
|
Chris@16
|
1698 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
|
Chris@16
|
1699 using vector_container<self_type>::operator ();
|
Chris@16
|
1700 #endif
|
Chris@16
|
1701 typedef typename ALLOC::size_type size_type;
|
Chris@16
|
1702 typedef typename ALLOC::difference_type difference_type;
|
Chris@16
|
1703 typedef T value_type;
|
Chris@16
|
1704 typedef const T &const_reference;
|
Chris@16
|
1705 typedef T &reference;
|
Chris@16
|
1706 typedef const vector_reference<const self_type> const_closure_type;
|
Chris@16
|
1707 typedef vector_reference<self_type> closure_type;
|
Chris@16
|
1708 typedef sparse_tag storage_category;
|
Chris@16
|
1709
|
Chris@16
|
1710 // Construction and destruction
|
Chris@16
|
1711 BOOST_UBLAS_INLINE
|
Chris@16
|
1712 zero_vector ():
|
Chris@16
|
1713 vector_container<self_type> (),
|
Chris@16
|
1714 size_ (0) {}
|
Chris@16
|
1715 explicit BOOST_UBLAS_INLINE
|
Chris@16
|
1716 zero_vector (size_type size):
|
Chris@16
|
1717 vector_container<self_type> (),
|
Chris@16
|
1718 size_ (size) {}
|
Chris@16
|
1719 BOOST_UBLAS_INLINE
|
Chris@16
|
1720 zero_vector (const zero_vector &v):
|
Chris@16
|
1721 vector_container<self_type> (),
|
Chris@16
|
1722 size_ (v.size_) {}
|
Chris@16
|
1723
|
Chris@16
|
1724 // Accessors
|
Chris@16
|
1725 BOOST_UBLAS_INLINE
|
Chris@16
|
1726 size_type size () const {
|
Chris@16
|
1727 return size_;
|
Chris@16
|
1728 }
|
Chris@16
|
1729
|
Chris@16
|
1730 // Resizing
|
Chris@16
|
1731 BOOST_UBLAS_INLINE
|
Chris@16
|
1732 void resize (size_type size, bool /*preserve*/ = true) {
|
Chris@16
|
1733 size_ = size;
|
Chris@16
|
1734 }
|
Chris@16
|
1735
|
Chris@16
|
1736 // Element support
|
Chris@16
|
1737 BOOST_UBLAS_INLINE
|
Chris@101
|
1738 const_pointer find_element (size_type /*i*/) const {
|
Chris@16
|
1739 return & zero_;
|
Chris@16
|
1740 }
|
Chris@16
|
1741
|
Chris@16
|
1742 // Element access
|
Chris@16
|
1743 BOOST_UBLAS_INLINE
|
Chris@16
|
1744 const_reference operator () (size_type /* i */) const {
|
Chris@16
|
1745 return zero_;
|
Chris@16
|
1746 }
|
Chris@16
|
1747
|
Chris@16
|
1748 BOOST_UBLAS_INLINE
|
Chris@16
|
1749 const_reference operator [] (size_type i) const {
|
Chris@16
|
1750 return (*this) (i);
|
Chris@16
|
1751 }
|
Chris@16
|
1752
|
Chris@16
|
1753 // Assignment
|
Chris@16
|
1754 BOOST_UBLAS_INLINE
|
Chris@16
|
1755 zero_vector &operator = (const zero_vector &v) {
|
Chris@16
|
1756 size_ = v.size_;
|
Chris@16
|
1757 return *this;
|
Chris@16
|
1758 }
|
Chris@16
|
1759 BOOST_UBLAS_INLINE
|
Chris@16
|
1760 zero_vector &assign_temporary (zero_vector &v) {
|
Chris@16
|
1761 swap (v);
|
Chris@16
|
1762 return *this;
|
Chris@16
|
1763 }
|
Chris@16
|
1764
|
Chris@16
|
1765 // Swapping
|
Chris@16
|
1766 BOOST_UBLAS_INLINE
|
Chris@16
|
1767 void swap (zero_vector &v) {
|
Chris@16
|
1768 if (this != &v) {
|
Chris@16
|
1769 std::swap (size_, v.size_);
|
Chris@16
|
1770 }
|
Chris@16
|
1771 }
|
Chris@16
|
1772 BOOST_UBLAS_INLINE
|
Chris@16
|
1773 friend void swap (zero_vector &v1, zero_vector &v2) {
|
Chris@16
|
1774 v1.swap (v2);
|
Chris@16
|
1775 }
|
Chris@16
|
1776
|
Chris@16
|
1777 // Iterator types
|
Chris@16
|
1778 public:
|
Chris@16
|
1779 class const_iterator;
|
Chris@16
|
1780
|
Chris@16
|
1781 // Element lookup
|
Chris@16
|
1782 BOOST_UBLAS_INLINE
|
Chris@16
|
1783 const_iterator find (size_type /*i*/) const {
|
Chris@16
|
1784 return const_iterator (*this);
|
Chris@16
|
1785 }
|
Chris@16
|
1786
|
Chris@16
|
1787 class const_iterator:
|
Chris@16
|
1788 public container_const_reference<zero_vector>,
|
Chris@16
|
1789 public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,
|
Chris@16
|
1790 const_iterator, value_type> {
|
Chris@16
|
1791 public:
|
Chris@16
|
1792 typedef typename zero_vector::difference_type difference_type;
|
Chris@16
|
1793 typedef typename zero_vector::value_type value_type;
|
Chris@16
|
1794 typedef typename zero_vector::const_reference reference;
|
Chris@16
|
1795 typedef typename zero_vector::const_pointer pointer;
|
Chris@16
|
1796
|
Chris@16
|
1797 // Construction and destruction
|
Chris@16
|
1798 BOOST_UBLAS_INLINE
|
Chris@16
|
1799 const_iterator ():
|
Chris@16
|
1800 container_const_reference<self_type> () {}
|
Chris@16
|
1801 BOOST_UBLAS_INLINE
|
Chris@16
|
1802 const_iterator (const self_type &v):
|
Chris@16
|
1803 container_const_reference<self_type> (v) {}
|
Chris@16
|
1804
|
Chris@16
|
1805 // Arithmetic
|
Chris@16
|
1806 BOOST_UBLAS_INLINE
|
Chris@16
|
1807 const_iterator &operator ++ () {
|
Chris@16
|
1808 BOOST_UBLAS_CHECK_FALSE (bad_index ());
|
Chris@16
|
1809 return *this;
|
Chris@16
|
1810 }
|
Chris@16
|
1811 BOOST_UBLAS_INLINE
|
Chris@16
|
1812 const_iterator &operator -- () {
|
Chris@16
|
1813 BOOST_UBLAS_CHECK_FALSE (bad_index ());
|
Chris@16
|
1814 return *this;
|
Chris@16
|
1815 }
|
Chris@16
|
1816
|
Chris@16
|
1817 // Dereference
|
Chris@16
|
1818 BOOST_UBLAS_INLINE
|
Chris@16
|
1819 const_reference operator * () const {
|
Chris@16
|
1820 BOOST_UBLAS_CHECK_FALSE (bad_index ());
|
Chris@16
|
1821 return zero_; // arbitary return value
|
Chris@16
|
1822 }
|
Chris@16
|
1823
|
Chris@16
|
1824 // Index
|
Chris@16
|
1825 BOOST_UBLAS_INLINE
|
Chris@16
|
1826 size_type index () const {
|
Chris@16
|
1827 BOOST_UBLAS_CHECK_FALSE (bad_index ());
|
Chris@16
|
1828 return 0; // arbitary return value
|
Chris@16
|
1829 }
|
Chris@16
|
1830
|
Chris@16
|
1831 // Assignment
|
Chris@16
|
1832 BOOST_UBLAS_INLINE
|
Chris@16
|
1833 const_iterator &operator = (const const_iterator &it) {
|
Chris@16
|
1834 container_const_reference<self_type>::assign (&it ());
|
Chris@16
|
1835 return *this;
|
Chris@16
|
1836 }
|
Chris@16
|
1837
|
Chris@16
|
1838 // Comparison
|
Chris@16
|
1839 BOOST_UBLAS_INLINE
|
Chris@16
|
1840 bool operator == (const const_iterator &it) const {
|
Chris@16
|
1841 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
1842 detail::ignore_unused_variable_warning(it);
|
Chris@16
|
1843 return true;
|
Chris@16
|
1844 }
|
Chris@16
|
1845 };
|
Chris@16
|
1846
|
Chris@16
|
1847 typedef const_iterator iterator;
|
Chris@16
|
1848
|
Chris@16
|
1849 BOOST_UBLAS_INLINE
|
Chris@16
|
1850 const_iterator begin () const {
|
Chris@16
|
1851 return const_iterator (*this);
|
Chris@16
|
1852 }
|
Chris@101
|
1853 BOOST_UBLAS_INLINE
|
Chris@101
|
1854 const_iterator cbegin () const {
|
Chris@101
|
1855 return begin ();
|
Chris@101
|
1856 }
|
Chris@16
|
1857 BOOST_UBLAS_INLINE
|
Chris@16
|
1858 const_iterator end () const {
|
Chris@16
|
1859 return const_iterator (*this);
|
Chris@16
|
1860 }
|
Chris@101
|
1861 BOOST_UBLAS_INLINE
|
Chris@101
|
1862 const_iterator cend () const {
|
Chris@101
|
1863 return end ();
|
Chris@101
|
1864 }
|
Chris@16
|
1865
|
Chris@16
|
1866 // Reverse iterator
|
Chris@16
|
1867 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
|
Chris@16
|
1868
|
Chris@16
|
1869 BOOST_UBLAS_INLINE
|
Chris@16
|
1870 const_reverse_iterator rbegin () const {
|
Chris@16
|
1871 return const_reverse_iterator (end ());
|
Chris@16
|
1872 }
|
Chris@101
|
1873 BOOST_UBLAS_INLINE
|
Chris@101
|
1874 const_reverse_iterator crbegin () const {
|
Chris@101
|
1875 return rbegin ();
|
Chris@101
|
1876 }
|
Chris@16
|
1877 BOOST_UBLAS_INLINE
|
Chris@16
|
1878 const_reverse_iterator rend () const {
|
Chris@16
|
1879 return const_reverse_iterator (begin ());
|
Chris@16
|
1880 }
|
Chris@101
|
1881 BOOST_UBLAS_INLINE
|
Chris@101
|
1882 const_reverse_iterator crend () const {
|
Chris@101
|
1883 return rend ();
|
Chris@101
|
1884 }
|
Chris@16
|
1885
|
Chris@16
|
1886 // Serialization
|
Chris@16
|
1887 template<class Archive>
|
Chris@16
|
1888 void serialize(Archive & ar, const unsigned int /* file_version */){
|
Chris@16
|
1889 serialization::collection_size_type s (size_);
|
Chris@16
|
1890 ar & serialization::make_nvp("size",s);
|
Chris@16
|
1891 if (Archive::is_loading::value) {
|
Chris@16
|
1892 size_ = s;
|
Chris@16
|
1893 }
|
Chris@16
|
1894 }
|
Chris@16
|
1895
|
Chris@16
|
1896 private:
|
Chris@16
|
1897 size_type size_;
|
Chris@16
|
1898 typedef const value_type const_value_type;
|
Chris@16
|
1899 static const_value_type zero_;
|
Chris@16
|
1900 };
|
Chris@16
|
1901
|
Chris@16
|
1902 template<class T, class ALLOC>
|
Chris@16
|
1903 typename zero_vector<T, ALLOC>::const_value_type zero_vector<T, ALLOC>::zero_ = T(/*zero*/);
|
Chris@16
|
1904
|
Chris@16
|
1905
|
Chris@16
|
1906 // Unit vector class
|
Chris@16
|
1907 /// \brief unit_vector represents a canonical unit vector
|
Chris@16
|
1908 /// unit_vector represents a canonical unit vector. The \e k-th unit vector of dimension \f$n\f$ holds 0 for every value \f$u_i\f$ s.t. \f$i \neq k\f$ and 1 when \f$i=k\f$.
|
Chris@16
|
1909 /// At construction, the value \e k is given after the dimension of the vector.
|
Chris@16
|
1910 /// \tparam T is the type of elements in the vector. They must be 0 and 1 assignable in order for the vector to have its unit-vector semantic.
|
Chris@16
|
1911 /// \tparam ALLOC a specific allocator can be specified if needed. Most of the time this parameter is omited.
|
Chris@16
|
1912 template<class T, class ALLOC>
|
Chris@16
|
1913 class unit_vector:
|
Chris@16
|
1914 public vector_container<unit_vector<T, ALLOC> > {
|
Chris@16
|
1915
|
Chris@16
|
1916 typedef const T *const_pointer;
|
Chris@16
|
1917 typedef unit_vector<T, ALLOC> self_type;
|
Chris@16
|
1918 public:
|
Chris@16
|
1919 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
|
Chris@16
|
1920 using vector_container<self_type>::operator ();
|
Chris@16
|
1921 #endif
|
Chris@16
|
1922 typedef typename ALLOC::size_type size_type;
|
Chris@16
|
1923 typedef typename ALLOC::difference_type difference_type;
|
Chris@16
|
1924 typedef T value_type;
|
Chris@16
|
1925 typedef const T &const_reference;
|
Chris@16
|
1926 typedef T &reference;
|
Chris@16
|
1927 typedef const vector_reference<const self_type> const_closure_type;
|
Chris@16
|
1928 typedef vector_reference<self_type> closure_type;
|
Chris@16
|
1929 typedef sparse_tag storage_category;
|
Chris@16
|
1930
|
Chris@16
|
1931 // Construction and destruction
|
Chris@16
|
1932 /// \brief Simple constructor with dimension and index 0
|
Chris@16
|
1933 BOOST_UBLAS_INLINE
|
Chris@16
|
1934 unit_vector ():
|
Chris@16
|
1935 vector_container<self_type> (),
|
Chris@16
|
1936 size_ (0), index_ (0) {}
|
Chris@16
|
1937
|
Chris@16
|
1938 /// \brief Constructor of unit_vector
|
Chris@16
|
1939 /// \param size is the dimension of the vector
|
Chris@16
|
1940 /// \param index is the order of the vector
|
Chris@16
|
1941 BOOST_UBLAS_INLINE
|
Chris@16
|
1942 explicit unit_vector (size_type size, size_type index = 0):
|
Chris@16
|
1943 vector_container<self_type> (),
|
Chris@16
|
1944 size_ (size), index_ (index) {}
|
Chris@16
|
1945
|
Chris@16
|
1946 /// \brief Copy-constructor
|
Chris@16
|
1947 BOOST_UBLAS_INLINE
|
Chris@16
|
1948 unit_vector (const unit_vector &v):
|
Chris@16
|
1949 vector_container<self_type> (),
|
Chris@16
|
1950 size_ (v.size_), index_ (v.index_) {}
|
Chris@16
|
1951
|
Chris@16
|
1952 // Accessors
|
Chris@16
|
1953 //----------
|
Chris@16
|
1954
|
Chris@16
|
1955 /// \brief Return the size (dimension) of the vector
|
Chris@16
|
1956 BOOST_UBLAS_INLINE
|
Chris@16
|
1957 size_type size () const {
|
Chris@16
|
1958 return size_;
|
Chris@16
|
1959 }
|
Chris@16
|
1960
|
Chris@16
|
1961 /// \brief Return the order of the unit vector
|
Chris@16
|
1962 BOOST_UBLAS_INLINE
|
Chris@16
|
1963 size_type index () const {
|
Chris@16
|
1964 return index_;
|
Chris@16
|
1965 }
|
Chris@16
|
1966
|
Chris@16
|
1967 // Resizing
|
Chris@16
|
1968 // --------
|
Chris@16
|
1969
|
Chris@16
|
1970 /// \brief Resize the vector. The values are preserved by default (i.e. the index does not change)
|
Chris@16
|
1971 /// \param size is the new size of the vector
|
Chris@16
|
1972 BOOST_UBLAS_INLINE
|
Chris@16
|
1973 void resize (size_type size, bool /*preserve*/ = true) {
|
Chris@16
|
1974 size_ = size;
|
Chris@16
|
1975 }
|
Chris@16
|
1976
|
Chris@16
|
1977 // Element support
|
Chris@16
|
1978 // ---------------
|
Chris@16
|
1979
|
Chris@16
|
1980 /// \brief Return a const pointer to the element of index i
|
Chris@16
|
1981 BOOST_UBLAS_INLINE
|
Chris@16
|
1982 const_pointer find_element (size_type i) const {
|
Chris@16
|
1983 if (i == index_)
|
Chris@16
|
1984 return & one_;
|
Chris@16
|
1985 else
|
Chris@16
|
1986 return & zero_;
|
Chris@16
|
1987 }
|
Chris@16
|
1988
|
Chris@16
|
1989 // Element access
|
Chris@16
|
1990 BOOST_UBLAS_INLINE
|
Chris@16
|
1991 const_reference operator () (size_type i) const {
|
Chris@16
|
1992 if (i == index_)
|
Chris@16
|
1993 return one_;
|
Chris@16
|
1994 else
|
Chris@16
|
1995 return zero_;
|
Chris@16
|
1996 }
|
Chris@16
|
1997
|
Chris@16
|
1998 BOOST_UBLAS_INLINE
|
Chris@16
|
1999 const_reference operator [] (size_type i) const {
|
Chris@16
|
2000 return (*this) (i);
|
Chris@16
|
2001 }
|
Chris@16
|
2002
|
Chris@16
|
2003 // Assignment
|
Chris@16
|
2004 BOOST_UBLAS_INLINE
|
Chris@16
|
2005 unit_vector &operator = (const unit_vector &v) {
|
Chris@16
|
2006 size_ = v.size_;
|
Chris@16
|
2007 index_ = v.index_;
|
Chris@16
|
2008 return *this;
|
Chris@16
|
2009 }
|
Chris@16
|
2010 BOOST_UBLAS_INLINE
|
Chris@16
|
2011 unit_vector &assign_temporary (unit_vector &v) {
|
Chris@16
|
2012 swap (v);
|
Chris@16
|
2013 return *this;
|
Chris@16
|
2014 }
|
Chris@16
|
2015
|
Chris@16
|
2016 // Swapping
|
Chris@16
|
2017 BOOST_UBLAS_INLINE
|
Chris@16
|
2018 void swap (unit_vector &v) {
|
Chris@16
|
2019 if (this != &v) {
|
Chris@16
|
2020 std::swap (size_, v.size_);
|
Chris@16
|
2021 std::swap (index_, v.index_);
|
Chris@16
|
2022 }
|
Chris@16
|
2023 }
|
Chris@16
|
2024 BOOST_UBLAS_INLINE
|
Chris@16
|
2025 friend void swap (unit_vector &v1, unit_vector &v2) {
|
Chris@16
|
2026 v1.swap (v2);
|
Chris@16
|
2027 }
|
Chris@16
|
2028
|
Chris@16
|
2029 // Iterator types
|
Chris@16
|
2030 private:
|
Chris@16
|
2031 // Use bool to indicate begin (one_ as value)
|
Chris@16
|
2032 typedef bool const_subiterator_type;
|
Chris@16
|
2033 public:
|
Chris@16
|
2034 class const_iterator;
|
Chris@16
|
2035
|
Chris@16
|
2036 // Element lookup
|
Chris@16
|
2037 BOOST_UBLAS_INLINE
|
Chris@16
|
2038 const_iterator find (size_type i) const {
|
Chris@16
|
2039 return const_iterator (*this, i <= index_);
|
Chris@16
|
2040 }
|
Chris@16
|
2041
|
Chris@16
|
2042 class const_iterator:
|
Chris@16
|
2043 public container_const_reference<unit_vector>,
|
Chris@16
|
2044 public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,
|
Chris@16
|
2045 const_iterator, value_type> {
|
Chris@16
|
2046 public:
|
Chris@16
|
2047 typedef typename unit_vector::difference_type difference_type;
|
Chris@16
|
2048 typedef typename unit_vector::value_type value_type;
|
Chris@16
|
2049 typedef typename unit_vector::const_reference reference;
|
Chris@16
|
2050 typedef typename unit_vector::const_pointer pointer;
|
Chris@16
|
2051
|
Chris@16
|
2052 // Construction and destruction
|
Chris@16
|
2053 BOOST_UBLAS_INLINE
|
Chris@16
|
2054 const_iterator ():
|
Chris@16
|
2055 container_const_reference<unit_vector> (), it_ () {}
|
Chris@16
|
2056 BOOST_UBLAS_INLINE
|
Chris@16
|
2057 const_iterator (const unit_vector &v, const const_subiterator_type &it):
|
Chris@16
|
2058 container_const_reference<unit_vector> (v), it_ (it) {}
|
Chris@16
|
2059
|
Chris@16
|
2060 // Arithmetic
|
Chris@16
|
2061 BOOST_UBLAS_INLINE
|
Chris@16
|
2062 const_iterator &operator ++ () {
|
Chris@16
|
2063 BOOST_UBLAS_CHECK (it_, bad_index ());
|
Chris@16
|
2064 it_ = !it_;
|
Chris@16
|
2065 return *this;
|
Chris@16
|
2066 }
|
Chris@16
|
2067 BOOST_UBLAS_INLINE
|
Chris@16
|
2068 const_iterator &operator -- () {
|
Chris@16
|
2069 BOOST_UBLAS_CHECK (!it_, bad_index ());
|
Chris@16
|
2070 it_ = !it_;
|
Chris@16
|
2071 return *this;
|
Chris@16
|
2072 }
|
Chris@16
|
2073
|
Chris@16
|
2074 // Dereference
|
Chris@16
|
2075 BOOST_UBLAS_INLINE
|
Chris@16
|
2076 const_reference operator * () const {
|
Chris@16
|
2077 BOOST_UBLAS_CHECK (it_, bad_index ());
|
Chris@16
|
2078 return one_;
|
Chris@16
|
2079 }
|
Chris@16
|
2080
|
Chris@16
|
2081 // Index
|
Chris@16
|
2082 BOOST_UBLAS_INLINE
|
Chris@16
|
2083 size_type index () const {
|
Chris@16
|
2084 BOOST_UBLAS_CHECK (it_, bad_index ());
|
Chris@16
|
2085 return (*this) ().index_;
|
Chris@16
|
2086 }
|
Chris@16
|
2087
|
Chris@16
|
2088 // Assignment
|
Chris@16
|
2089 BOOST_UBLAS_INLINE
|
Chris@16
|
2090 const_iterator &operator = (const const_iterator &it) {
|
Chris@16
|
2091 container_const_reference<unit_vector>::assign (&it ());
|
Chris@16
|
2092 it_ = it.it_;
|
Chris@16
|
2093 return *this;
|
Chris@16
|
2094 }
|
Chris@16
|
2095
|
Chris@16
|
2096 // Comparison
|
Chris@16
|
2097 BOOST_UBLAS_INLINE
|
Chris@16
|
2098 bool operator == (const const_iterator &it) const {
|
Chris@16
|
2099 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2100 return it_ == it.it_;
|
Chris@16
|
2101 }
|
Chris@16
|
2102
|
Chris@16
|
2103 private:
|
Chris@16
|
2104 const_subiterator_type it_;
|
Chris@16
|
2105 };
|
Chris@16
|
2106
|
Chris@16
|
2107 typedef const_iterator iterator;
|
Chris@16
|
2108
|
Chris@16
|
2109 BOOST_UBLAS_INLINE
|
Chris@16
|
2110 const_iterator begin () const {
|
Chris@16
|
2111 return const_iterator (*this, true);
|
Chris@16
|
2112 }
|
Chris@101
|
2113 BOOST_UBLAS_INLINE
|
Chris@101
|
2114 const_iterator cbegin () const {
|
Chris@101
|
2115 return begin ();
|
Chris@101
|
2116 }
|
Chris@16
|
2117 BOOST_UBLAS_INLINE
|
Chris@16
|
2118 const_iterator end () const {
|
Chris@16
|
2119 return const_iterator (*this, false);
|
Chris@16
|
2120 }
|
Chris@101
|
2121 BOOST_UBLAS_INLINE
|
Chris@101
|
2122 const_iterator cend () const {
|
Chris@101
|
2123 return end ();
|
Chris@101
|
2124 }
|
Chris@16
|
2125
|
Chris@16
|
2126 // Reverse iterator
|
Chris@16
|
2127 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
|
Chris@16
|
2128
|
Chris@16
|
2129 BOOST_UBLAS_INLINE
|
Chris@16
|
2130 const_reverse_iterator rbegin () const {
|
Chris@16
|
2131 return const_reverse_iterator (end ());
|
Chris@16
|
2132 }
|
Chris@101
|
2133 BOOST_UBLAS_INLINE
|
Chris@101
|
2134 const_reverse_iterator crbegin () const {
|
Chris@101
|
2135 return rbegin ();
|
Chris@101
|
2136 }
|
Chris@16
|
2137 BOOST_UBLAS_INLINE
|
Chris@16
|
2138 const_reverse_iterator rend () const {
|
Chris@16
|
2139 return const_reverse_iterator (begin ());
|
Chris@16
|
2140 }
|
Chris@101
|
2141 BOOST_UBLAS_INLINE
|
Chris@101
|
2142 const_reverse_iterator crend () const {
|
Chris@101
|
2143 return rend ();
|
Chris@101
|
2144 }
|
Chris@16
|
2145
|
Chris@16
|
2146 // Serialization
|
Chris@16
|
2147 template<class Archive>
|
Chris@16
|
2148 void serialize(Archive & ar, const unsigned int /* file_version */){
|
Chris@16
|
2149 serialization::collection_size_type s (size_);
|
Chris@16
|
2150 ar & serialization::make_nvp("size",s);
|
Chris@16
|
2151 if (Archive::is_loading::value) {
|
Chris@16
|
2152 size_ = s;
|
Chris@16
|
2153 }
|
Chris@16
|
2154 ar & serialization::make_nvp("index", index_);
|
Chris@16
|
2155 }
|
Chris@16
|
2156
|
Chris@16
|
2157 private:
|
Chris@16
|
2158 size_type size_;
|
Chris@16
|
2159 size_type index_;
|
Chris@16
|
2160 typedef const value_type const_value_type;
|
Chris@16
|
2161 static const_value_type zero_;
|
Chris@16
|
2162 static const_value_type one_;
|
Chris@16
|
2163 };
|
Chris@16
|
2164
|
Chris@16
|
2165 template<class T, class ALLOC>
|
Chris@16
|
2166 typename unit_vector<T, ALLOC>::const_value_type unit_vector<T, ALLOC>::zero_ = T(/*zero*/);
|
Chris@16
|
2167 template<class T, class ALLOC>
|
Chris@16
|
2168 typename unit_vector<T, ALLOC>::const_value_type unit_vector<T, ALLOC>::one_ (1); // ISSUE: need 'one'-traits here
|
Chris@16
|
2169
|
Chris@16
|
2170 /// \brief A scalar (i.e. unique value) vector of type \c T and a given \c size
|
Chris@16
|
2171 /// A scalar (i.e. unique value) vector of type \c T and a given \c size. This is a virtual vector in the sense that no memory is allocated
|
Chris@16
|
2172 /// for storing the unique value more than once: it still acts like any other vector. However assigning a new value will change all the value at once.
|
Chris@16
|
2173 /// vector into a normal vector. It must first be assigned to another normal vector by any suitable means. Its memory footprint is constant.
|
Chris@16
|
2174 /// \tparam T type of the objects stored in the vector: it can be anything even if most of the time, scalar types will be used like \c double or \c int. Complex types can be used, or even classes like boost::interval.
|
Chris@16
|
2175 template<class T, class ALLOC>
|
Chris@16
|
2176 class scalar_vector:
|
Chris@16
|
2177 public vector_container<scalar_vector<T, ALLOC> > {
|
Chris@16
|
2178
|
Chris@16
|
2179 typedef const T *const_pointer;
|
Chris@16
|
2180 typedef scalar_vector<T, ALLOC> self_type;
|
Chris@16
|
2181 public:
|
Chris@16
|
2182 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
|
Chris@16
|
2183 using vector_container<self_type>::operator ();
|
Chris@16
|
2184 #endif
|
Chris@16
|
2185 typedef typename ALLOC::size_type size_type;
|
Chris@16
|
2186 typedef typename ALLOC::difference_type difference_type;
|
Chris@16
|
2187 typedef T value_type;
|
Chris@16
|
2188 typedef const T &const_reference;
|
Chris@16
|
2189 typedef T &reference;
|
Chris@16
|
2190 typedef const vector_reference<const self_type> const_closure_type;
|
Chris@16
|
2191 typedef vector_reference<self_type> closure_type;
|
Chris@16
|
2192 typedef dense_tag storage_category;
|
Chris@16
|
2193
|
Chris@16
|
2194 // Construction and destruction
|
Chris@16
|
2195 BOOST_UBLAS_INLINE
|
Chris@16
|
2196 scalar_vector ():
|
Chris@16
|
2197 vector_container<self_type> (),
|
Chris@16
|
2198 size_ (0), value_ () {}
|
Chris@16
|
2199 BOOST_UBLAS_INLINE
|
Chris@16
|
2200 explicit scalar_vector (size_type size, const value_type &value = value_type(1)):
|
Chris@16
|
2201 vector_container<self_type> (),
|
Chris@16
|
2202 size_ (size), value_ (value) {}
|
Chris@16
|
2203 BOOST_UBLAS_INLINE
|
Chris@16
|
2204 scalar_vector (const scalar_vector &v):
|
Chris@16
|
2205 vector_container<self_type> (),
|
Chris@16
|
2206 size_ (v.size_), value_ (v.value_) {}
|
Chris@16
|
2207
|
Chris@16
|
2208 // Accessors
|
Chris@16
|
2209 BOOST_UBLAS_INLINE
|
Chris@16
|
2210 size_type size () const {
|
Chris@16
|
2211 return size_;
|
Chris@16
|
2212 }
|
Chris@16
|
2213
|
Chris@16
|
2214 // Resizing
|
Chris@16
|
2215 BOOST_UBLAS_INLINE
|
Chris@16
|
2216 void resize (size_type size, bool /*preserve*/ = true) {
|
Chris@16
|
2217 size_ = size;
|
Chris@16
|
2218 }
|
Chris@16
|
2219
|
Chris@16
|
2220 // Element support
|
Chris@16
|
2221 BOOST_UBLAS_INLINE
|
Chris@16
|
2222 const_pointer find_element (size_type /*i*/) const {
|
Chris@16
|
2223 return & value_;
|
Chris@16
|
2224 }
|
Chris@16
|
2225
|
Chris@16
|
2226 // Element access
|
Chris@16
|
2227 BOOST_UBLAS_INLINE
|
Chris@16
|
2228 const_reference operator () (size_type /*i*/) const {
|
Chris@16
|
2229 return value_;
|
Chris@16
|
2230 }
|
Chris@16
|
2231
|
Chris@16
|
2232 BOOST_UBLAS_INLINE
|
Chris@16
|
2233 const_reference operator [] (size_type /*i*/) const {
|
Chris@16
|
2234 return value_;
|
Chris@16
|
2235 }
|
Chris@16
|
2236
|
Chris@16
|
2237 // Assignment
|
Chris@16
|
2238 BOOST_UBLAS_INLINE
|
Chris@16
|
2239 scalar_vector &operator = (const scalar_vector &v) {
|
Chris@16
|
2240 size_ = v.size_;
|
Chris@16
|
2241 value_ = v.value_;
|
Chris@16
|
2242 return *this;
|
Chris@16
|
2243 }
|
Chris@16
|
2244 BOOST_UBLAS_INLINE
|
Chris@16
|
2245 scalar_vector &assign_temporary (scalar_vector &v) {
|
Chris@16
|
2246 swap (v);
|
Chris@16
|
2247 return *this;
|
Chris@16
|
2248 }
|
Chris@16
|
2249
|
Chris@16
|
2250 // Swapping
|
Chris@16
|
2251 BOOST_UBLAS_INLINE
|
Chris@16
|
2252 void swap (scalar_vector &v) {
|
Chris@16
|
2253 if (this != &v) {
|
Chris@16
|
2254 std::swap (size_, v.size_);
|
Chris@16
|
2255 std::swap (value_, v.value_);
|
Chris@16
|
2256 }
|
Chris@16
|
2257 }
|
Chris@16
|
2258 BOOST_UBLAS_INLINE
|
Chris@16
|
2259 friend void swap (scalar_vector &v1, scalar_vector &v2) {
|
Chris@16
|
2260 v1.swap (v2);
|
Chris@16
|
2261 }
|
Chris@16
|
2262
|
Chris@16
|
2263 // Iterator types
|
Chris@16
|
2264 private:
|
Chris@16
|
2265 // Use an index
|
Chris@16
|
2266 typedef size_type const_subiterator_type;
|
Chris@16
|
2267
|
Chris@16
|
2268 public:
|
Chris@16
|
2269 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
2270 typedef indexed_const_iterator<self_type, dense_random_access_iterator_tag> iterator;
|
Chris@16
|
2271 typedef indexed_const_iterator<self_type, dense_random_access_iterator_tag> const_iterator;
|
Chris@16
|
2272 #else
|
Chris@16
|
2273 class const_iterator;
|
Chris@16
|
2274 #endif
|
Chris@16
|
2275
|
Chris@16
|
2276 // Element lookup
|
Chris@16
|
2277 BOOST_UBLAS_INLINE
|
Chris@16
|
2278 const_iterator find (size_type i) const {
|
Chris@16
|
2279 return const_iterator (*this, i);
|
Chris@16
|
2280 }
|
Chris@16
|
2281
|
Chris@16
|
2282 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
2283 class const_iterator:
|
Chris@16
|
2284 public container_const_reference<scalar_vector>,
|
Chris@16
|
2285 public random_access_iterator_base<dense_random_access_iterator_tag,
|
Chris@16
|
2286 const_iterator, value_type> {
|
Chris@16
|
2287 public:
|
Chris@16
|
2288 typedef typename scalar_vector::difference_type difference_type;
|
Chris@16
|
2289 typedef typename scalar_vector::value_type value_type;
|
Chris@16
|
2290 typedef typename scalar_vector::const_reference reference;
|
Chris@16
|
2291 typedef typename scalar_vector::const_pointer pointer;
|
Chris@16
|
2292
|
Chris@16
|
2293 // Construction and destruction
|
Chris@16
|
2294 BOOST_UBLAS_INLINE
|
Chris@16
|
2295 const_iterator ():
|
Chris@16
|
2296 container_const_reference<scalar_vector> (), it_ () {}
|
Chris@16
|
2297 BOOST_UBLAS_INLINE
|
Chris@16
|
2298 const_iterator (const scalar_vector &v, const const_subiterator_type &it):
|
Chris@16
|
2299 container_const_reference<scalar_vector> (v), it_ (it) {}
|
Chris@16
|
2300
|
Chris@16
|
2301 // Arithmetic
|
Chris@16
|
2302 BOOST_UBLAS_INLINE
|
Chris@16
|
2303 const_iterator &operator ++ () {
|
Chris@16
|
2304 ++ it_;
|
Chris@16
|
2305 return *this;
|
Chris@16
|
2306 }
|
Chris@16
|
2307 BOOST_UBLAS_INLINE
|
Chris@16
|
2308 const_iterator &operator -- () {
|
Chris@16
|
2309 -- it_;
|
Chris@16
|
2310 return *this;
|
Chris@16
|
2311 }
|
Chris@16
|
2312 BOOST_UBLAS_INLINE
|
Chris@16
|
2313 const_iterator &operator += (difference_type n) {
|
Chris@16
|
2314 it_ += n;
|
Chris@16
|
2315 return *this;
|
Chris@16
|
2316 }
|
Chris@16
|
2317 BOOST_UBLAS_INLINE
|
Chris@16
|
2318 const_iterator &operator -= (difference_type n) {
|
Chris@16
|
2319 it_ -= n;
|
Chris@16
|
2320 return *this;
|
Chris@16
|
2321 }
|
Chris@16
|
2322 BOOST_UBLAS_INLINE
|
Chris@16
|
2323 difference_type operator - (const const_iterator &it) const {
|
Chris@16
|
2324 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2325 return it_ - it.it_;
|
Chris@16
|
2326 }
|
Chris@16
|
2327
|
Chris@16
|
2328 // Dereference
|
Chris@16
|
2329 BOOST_UBLAS_INLINE
|
Chris@16
|
2330 const_reference operator * () const {
|
Chris@16
|
2331 BOOST_UBLAS_CHECK (it_ < (*this) ().size (), bad_index ());
|
Chris@16
|
2332 return (*this) () (index ());
|
Chris@16
|
2333 }
|
Chris@16
|
2334 BOOST_UBLAS_INLINE
|
Chris@16
|
2335 const_reference operator [] (difference_type n) const {
|
Chris@16
|
2336 return *(*this + n);
|
Chris@16
|
2337 }
|
Chris@16
|
2338
|
Chris@16
|
2339 // Index
|
Chris@16
|
2340 BOOST_UBLAS_INLINE
|
Chris@16
|
2341 size_type index () const {
|
Chris@16
|
2342 BOOST_UBLAS_CHECK (it_ < (*this) ().size (), bad_index ());
|
Chris@16
|
2343 return it_;
|
Chris@16
|
2344 }
|
Chris@16
|
2345
|
Chris@16
|
2346 // Assignment
|
Chris@16
|
2347 BOOST_UBLAS_INLINE
|
Chris@16
|
2348 const_iterator &operator = (const const_iterator &it) {
|
Chris@16
|
2349 container_const_reference<scalar_vector>::assign (&it ());
|
Chris@16
|
2350 it_ = it.it_;
|
Chris@16
|
2351 return *this;
|
Chris@16
|
2352 }
|
Chris@16
|
2353
|
Chris@16
|
2354 // Comparison
|
Chris@16
|
2355 BOOST_UBLAS_INLINE
|
Chris@16
|
2356 bool operator == (const const_iterator &it) const {
|
Chris@16
|
2357 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2358 return it_ == it.it_;
|
Chris@16
|
2359 }
|
Chris@16
|
2360 BOOST_UBLAS_INLINE
|
Chris@16
|
2361 bool operator < (const const_iterator &it) const {
|
Chris@16
|
2362 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2363 return it_ < it.it_;
|
Chris@16
|
2364 }
|
Chris@16
|
2365
|
Chris@16
|
2366 private:
|
Chris@16
|
2367 const_subiterator_type it_;
|
Chris@16
|
2368 };
|
Chris@16
|
2369
|
Chris@16
|
2370 typedef const_iterator iterator;
|
Chris@16
|
2371 #endif
|
Chris@16
|
2372
|
Chris@16
|
2373 BOOST_UBLAS_INLINE
|
Chris@16
|
2374 const_iterator begin () const {
|
Chris@16
|
2375 return find (0);
|
Chris@16
|
2376 }
|
Chris@101
|
2377 BOOST_UBLAS_INLINE
|
Chris@101
|
2378 const_iterator cbegin () const {
|
Chris@101
|
2379 return begin ();
|
Chris@101
|
2380 }
|
Chris@16
|
2381 BOOST_UBLAS_INLINE
|
Chris@16
|
2382 const_iterator end () const {
|
Chris@16
|
2383 return find (size_);
|
Chris@16
|
2384 }
|
Chris@101
|
2385 BOOST_UBLAS_INLINE
|
Chris@101
|
2386 const_iterator cend () const {
|
Chris@101
|
2387 return end ();
|
Chris@101
|
2388 }
|
Chris@16
|
2389
|
Chris@16
|
2390 // Reverse iterator
|
Chris@16
|
2391 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
|
Chris@16
|
2392
|
Chris@16
|
2393 BOOST_UBLAS_INLINE
|
Chris@16
|
2394 const_reverse_iterator rbegin () const {
|
Chris@16
|
2395 return const_reverse_iterator (end ());
|
Chris@16
|
2396 }
|
Chris@101
|
2397 BOOST_UBLAS_INLINE
|
Chris@101
|
2398 const_reverse_iterator crbegin () const {
|
Chris@101
|
2399 return rbegin ();
|
Chris@101
|
2400 }
|
Chris@16
|
2401 BOOST_UBLAS_INLINE
|
Chris@16
|
2402 const_reverse_iterator rend () const {
|
Chris@16
|
2403 return const_reverse_iterator (begin ());
|
Chris@16
|
2404 }
|
Chris@101
|
2405 BOOST_UBLAS_INLINE
|
Chris@101
|
2406 const_reverse_iterator crend () const {
|
Chris@101
|
2407 return rend ();
|
Chris@101
|
2408 }
|
Chris@16
|
2409
|
Chris@16
|
2410 // Serialization
|
Chris@16
|
2411 template<class Archive>
|
Chris@16
|
2412 void serialize(Archive & ar, const unsigned int /* file_version */){
|
Chris@16
|
2413 serialization::collection_size_type s (size_);
|
Chris@16
|
2414 ar & serialization::make_nvp("size",s);
|
Chris@16
|
2415 if (Archive::is_loading::value) {
|
Chris@16
|
2416 size_ = s;
|
Chris@16
|
2417 }
|
Chris@16
|
2418 ar & serialization::make_nvp("value", value_);
|
Chris@16
|
2419 }
|
Chris@16
|
2420
|
Chris@16
|
2421 private:
|
Chris@16
|
2422 size_type size_;
|
Chris@16
|
2423 value_type value_;
|
Chris@16
|
2424 };
|
Chris@16
|
2425
|
Chris@16
|
2426 // ------------------------
|
Chris@16
|
2427 // Array based vector class
|
Chris@16
|
2428 // ------------------------
|
Chris@16
|
2429
|
Chris@16
|
2430 /// \brief A dense vector of values of type \c T with the given \c size. The data is stored as an ordinary C++ array \c T \c data_[M]
|
Chris@16
|
2431 template<class T, std::size_t N>
|
Chris@16
|
2432 class c_vector:
|
Chris@16
|
2433 public vector_container<c_vector<T, N> > {
|
Chris@16
|
2434
|
Chris@16
|
2435 typedef c_vector<T, N> self_type;
|
Chris@16
|
2436 public:
|
Chris@16
|
2437 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
|
Chris@16
|
2438 using vector_container<self_type>::operator ();
|
Chris@16
|
2439 #endif
|
Chris@16
|
2440 typedef std::size_t size_type;
|
Chris@16
|
2441 typedef std::ptrdiff_t difference_type;
|
Chris@16
|
2442 typedef T value_type;
|
Chris@16
|
2443 typedef const T &const_reference;
|
Chris@16
|
2444 typedef T &reference;
|
Chris@16
|
2445 typedef value_type array_type[N];
|
Chris@16
|
2446 typedef T *pointer;
|
Chris@16
|
2447 typedef const T *const_pointer;
|
Chris@16
|
2448 typedef const vector_reference<const self_type> const_closure_type;
|
Chris@16
|
2449 typedef vector_reference<self_type> closure_type;
|
Chris@16
|
2450 typedef self_type vector_temporary_type;
|
Chris@16
|
2451 typedef dense_tag storage_category;
|
Chris@16
|
2452
|
Chris@16
|
2453 // Construction and destruction
|
Chris@16
|
2454 BOOST_UBLAS_INLINE
|
Chris@16
|
2455 c_vector ():
|
Chris@16
|
2456 size_ (N) /* , data_ () */ {}
|
Chris@16
|
2457 explicit BOOST_UBLAS_INLINE
|
Chris@16
|
2458 c_vector (size_type size):
|
Chris@16
|
2459 size_ (size) /* , data_ () */ {
|
Chris@16
|
2460 if (size_ > N)
|
Chris@101
|
2461 bad_size ().raise ();
|
Chris@16
|
2462 }
|
Chris@16
|
2463 BOOST_UBLAS_INLINE
|
Chris@16
|
2464 c_vector (const c_vector &v):
|
Chris@16
|
2465 size_ (v.size_) /* , data_ () */ {
|
Chris@16
|
2466 if (size_ > N)
|
Chris@101
|
2467 bad_size ().raise ();
|
Chris@16
|
2468 assign(v);
|
Chris@16
|
2469 }
|
Chris@16
|
2470 template<class AE>
|
Chris@16
|
2471 BOOST_UBLAS_INLINE
|
Chris@16
|
2472 c_vector (const vector_expression<AE> &ae):
|
Chris@16
|
2473 size_ (ae ().size ()) /* , data_ () */ {
|
Chris@16
|
2474 if (size_ > N)
|
Chris@101
|
2475 bad_size ().raise ();
|
Chris@16
|
2476 vector_assign<scalar_assign> (*this, ae);
|
Chris@16
|
2477 }
|
Chris@16
|
2478
|
Chris@16
|
2479 // Accessors
|
Chris@16
|
2480 BOOST_UBLAS_INLINE
|
Chris@16
|
2481 size_type size () const {
|
Chris@16
|
2482 return size_;
|
Chris@16
|
2483 }
|
Chris@16
|
2484 BOOST_UBLAS_INLINE
|
Chris@16
|
2485 const_pointer data () const {
|
Chris@16
|
2486 return data_;
|
Chris@16
|
2487 }
|
Chris@16
|
2488 BOOST_UBLAS_INLINE
|
Chris@16
|
2489 pointer data () {
|
Chris@16
|
2490 return data_;
|
Chris@16
|
2491 }
|
Chris@16
|
2492
|
Chris@16
|
2493 // Resizing
|
Chris@16
|
2494 BOOST_UBLAS_INLINE
|
Chris@101
|
2495 void resize (size_type size, bool /*preserve*/ = true) {
|
Chris@16
|
2496 if (size > N)
|
Chris@101
|
2497 bad_size ().raise ();
|
Chris@16
|
2498 size_ = size;
|
Chris@16
|
2499 }
|
Chris@16
|
2500
|
Chris@16
|
2501 // Element support
|
Chris@16
|
2502 BOOST_UBLAS_INLINE
|
Chris@16
|
2503 pointer find_element (size_type i) {
|
Chris@16
|
2504 return const_cast<pointer> (const_cast<const self_type&>(*this).find_element (i));
|
Chris@16
|
2505 }
|
Chris@16
|
2506 BOOST_UBLAS_INLINE
|
Chris@16
|
2507 const_pointer find_element (size_type i) const {
|
Chris@16
|
2508 return & data_ [i];
|
Chris@16
|
2509 }
|
Chris@16
|
2510
|
Chris@16
|
2511 // Element access
|
Chris@16
|
2512 BOOST_UBLAS_INLINE
|
Chris@16
|
2513 const_reference operator () (size_type i) const {
|
Chris@16
|
2514 BOOST_UBLAS_CHECK (i < size_, bad_index ());
|
Chris@16
|
2515 return data_ [i];
|
Chris@16
|
2516 }
|
Chris@16
|
2517 BOOST_UBLAS_INLINE
|
Chris@16
|
2518 reference operator () (size_type i) {
|
Chris@16
|
2519 BOOST_UBLAS_CHECK (i < size_, bad_index ());
|
Chris@16
|
2520 return data_ [i];
|
Chris@16
|
2521 }
|
Chris@16
|
2522
|
Chris@16
|
2523 BOOST_UBLAS_INLINE
|
Chris@16
|
2524 const_reference operator [] (size_type i) const {
|
Chris@16
|
2525 return (*this) (i);
|
Chris@16
|
2526 }
|
Chris@16
|
2527 BOOST_UBLAS_INLINE
|
Chris@16
|
2528 reference operator [] (size_type i) {
|
Chris@16
|
2529 return (*this) (i);
|
Chris@16
|
2530 }
|
Chris@16
|
2531
|
Chris@16
|
2532 // Element assignment
|
Chris@16
|
2533 BOOST_UBLAS_INLINE
|
Chris@16
|
2534 reference insert_element (size_type i, const_reference t) {
|
Chris@16
|
2535 BOOST_UBLAS_CHECK (i < size_, bad_index ());
|
Chris@16
|
2536 return (data_ [i] = t);
|
Chris@16
|
2537 }
|
Chris@16
|
2538 BOOST_UBLAS_INLINE
|
Chris@16
|
2539 void erase_element (size_type i) {
|
Chris@16
|
2540 BOOST_UBLAS_CHECK (i < size_, bad_index ());
|
Chris@16
|
2541 data_ [i] = value_type/*zero*/();
|
Chris@16
|
2542 }
|
Chris@16
|
2543
|
Chris@16
|
2544 // Zeroing
|
Chris@16
|
2545 BOOST_UBLAS_INLINE
|
Chris@16
|
2546 void clear () {
|
Chris@16
|
2547 std::fill (data_, data_ + size_, value_type/*zero*/());
|
Chris@16
|
2548 }
|
Chris@16
|
2549
|
Chris@16
|
2550 // Assignment
|
Chris@16
|
2551 #ifdef BOOST_UBLAS_MOVE_SEMANTICS
|
Chris@16
|
2552
|
Chris@16
|
2553 /*! @note "pass by value" the key idea to enable move semantics */
|
Chris@16
|
2554 BOOST_UBLAS_INLINE
|
Chris@16
|
2555 c_vector &operator = (c_vector v) {
|
Chris@16
|
2556 assign_temporary(v);
|
Chris@16
|
2557 return *this;
|
Chris@16
|
2558 }
|
Chris@16
|
2559 #else
|
Chris@16
|
2560 BOOST_UBLAS_INLINE
|
Chris@16
|
2561 c_vector &operator = (const c_vector &v) {
|
Chris@16
|
2562 size_ = v.size_;
|
Chris@16
|
2563 std::copy (v.data_, v.data_ + v.size_, data_);
|
Chris@16
|
2564 return *this;
|
Chris@16
|
2565 }
|
Chris@16
|
2566 #endif
|
Chris@16
|
2567 template<class C> // Container assignment without temporary
|
Chris@16
|
2568 BOOST_UBLAS_INLINE
|
Chris@16
|
2569 c_vector &operator = (const vector_container<C> &v) {
|
Chris@16
|
2570 resize (v ().size (), false);
|
Chris@16
|
2571 assign (v);
|
Chris@16
|
2572 return *this;
|
Chris@16
|
2573 }
|
Chris@16
|
2574 BOOST_UBLAS_INLINE
|
Chris@16
|
2575 c_vector &assign_temporary (c_vector &v) {
|
Chris@16
|
2576 swap (v);
|
Chris@16
|
2577 return *this;
|
Chris@16
|
2578 }
|
Chris@16
|
2579 template<class AE>
|
Chris@16
|
2580 BOOST_UBLAS_INLINE
|
Chris@16
|
2581 c_vector &operator = (const vector_expression<AE> &ae) {
|
Chris@16
|
2582 self_type temporary (ae);
|
Chris@16
|
2583 return assign_temporary (temporary);
|
Chris@16
|
2584 }
|
Chris@16
|
2585 template<class AE>
|
Chris@16
|
2586 BOOST_UBLAS_INLINE
|
Chris@16
|
2587 c_vector &assign (const vector_expression<AE> &ae) {
|
Chris@16
|
2588 vector_assign<scalar_assign> (*this, ae);
|
Chris@16
|
2589 return *this;
|
Chris@16
|
2590 }
|
Chris@16
|
2591
|
Chris@16
|
2592 // Computed assignment
|
Chris@16
|
2593 template<class AE>
|
Chris@16
|
2594 BOOST_UBLAS_INLINE
|
Chris@16
|
2595 c_vector &operator += (const vector_expression<AE> &ae) {
|
Chris@16
|
2596 self_type temporary (*this + ae);
|
Chris@16
|
2597 return assign_temporary (temporary);
|
Chris@16
|
2598 }
|
Chris@16
|
2599 template<class C> // Container assignment without temporary
|
Chris@16
|
2600 BOOST_UBLAS_INLINE
|
Chris@16
|
2601 c_vector &operator += (const vector_container<C> &v) {
|
Chris@16
|
2602 plus_assign (v);
|
Chris@16
|
2603 return *this;
|
Chris@16
|
2604 }
|
Chris@16
|
2605 template<class AE>
|
Chris@16
|
2606 BOOST_UBLAS_INLINE
|
Chris@16
|
2607 c_vector &plus_assign (const vector_expression<AE> &ae) {
|
Chris@16
|
2608 vector_assign<scalar_plus_assign> ( *this, ae);
|
Chris@16
|
2609 return *this;
|
Chris@16
|
2610 }
|
Chris@16
|
2611 template<class AE>
|
Chris@16
|
2612 BOOST_UBLAS_INLINE
|
Chris@16
|
2613 c_vector &operator -= (const vector_expression<AE> &ae) {
|
Chris@16
|
2614 self_type temporary (*this - ae);
|
Chris@16
|
2615 return assign_temporary (temporary);
|
Chris@16
|
2616 }
|
Chris@16
|
2617 template<class C> // Container assignment without temporary
|
Chris@16
|
2618 BOOST_UBLAS_INLINE
|
Chris@16
|
2619 c_vector &operator -= (const vector_container<C> &v) {
|
Chris@16
|
2620 minus_assign (v);
|
Chris@16
|
2621 return *this;
|
Chris@16
|
2622 }
|
Chris@16
|
2623 template<class AE>
|
Chris@16
|
2624 BOOST_UBLAS_INLINE
|
Chris@16
|
2625 c_vector &minus_assign (const vector_expression<AE> &ae) {
|
Chris@16
|
2626 vector_assign<scalar_minus_assign> (*this, ae);
|
Chris@16
|
2627 return *this;
|
Chris@16
|
2628 }
|
Chris@16
|
2629 template<class AT>
|
Chris@16
|
2630 BOOST_UBLAS_INLINE
|
Chris@16
|
2631 c_vector &operator *= (const AT &at) {
|
Chris@16
|
2632 vector_assign_scalar<scalar_multiplies_assign> (*this, at);
|
Chris@16
|
2633 return *this;
|
Chris@16
|
2634 }
|
Chris@16
|
2635 template<class AT>
|
Chris@16
|
2636 BOOST_UBLAS_INLINE
|
Chris@16
|
2637 c_vector &operator /= (const AT &at) {
|
Chris@16
|
2638 vector_assign_scalar<scalar_divides_assign> (*this, at);
|
Chris@16
|
2639 return *this;
|
Chris@16
|
2640 }
|
Chris@16
|
2641
|
Chris@16
|
2642 // Swapping
|
Chris@16
|
2643 BOOST_UBLAS_INLINE
|
Chris@16
|
2644 void swap (c_vector &v) {
|
Chris@16
|
2645 if (this != &v) {
|
Chris@101
|
2646 BOOST_UBLAS_CHECK (size_ == v.size_, bad_size ());
|
Chris@16
|
2647 std::swap (size_, v.size_);
|
Chris@16
|
2648 std::swap_ranges (data_, data_ + size_, v.data_);
|
Chris@16
|
2649 }
|
Chris@16
|
2650 }
|
Chris@16
|
2651 BOOST_UBLAS_INLINE
|
Chris@16
|
2652 friend void swap (c_vector &v1, c_vector &v2) {
|
Chris@16
|
2653 v1.swap (v2);
|
Chris@16
|
2654 }
|
Chris@16
|
2655
|
Chris@16
|
2656 // Iterator types
|
Chris@16
|
2657 private:
|
Chris@16
|
2658 // Use pointers for iterator
|
Chris@16
|
2659 typedef const_pointer const_subiterator_type;
|
Chris@16
|
2660 typedef pointer subiterator_type;
|
Chris@16
|
2661
|
Chris@16
|
2662 public:
|
Chris@16
|
2663 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
2664 typedef indexed_iterator<self_type, dense_random_access_iterator_tag> iterator;
|
Chris@16
|
2665 typedef indexed_const_iterator<self_type, dense_random_access_iterator_tag> const_iterator;
|
Chris@16
|
2666 #else
|
Chris@16
|
2667 class const_iterator;
|
Chris@16
|
2668 class iterator;
|
Chris@16
|
2669 #endif
|
Chris@16
|
2670
|
Chris@16
|
2671 // Element lookup
|
Chris@16
|
2672 BOOST_UBLAS_INLINE
|
Chris@16
|
2673 const_iterator find (size_type i) const {
|
Chris@16
|
2674 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
2675 return const_iterator (*this, &data_ [i]);
|
Chris@16
|
2676 #else
|
Chris@16
|
2677 return const_iterator (*this, i);
|
Chris@16
|
2678 #endif
|
Chris@16
|
2679 }
|
Chris@16
|
2680 BOOST_UBLAS_INLINE
|
Chris@16
|
2681 iterator find (size_type i) {
|
Chris@16
|
2682 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
2683 return iterator (*this, &data_ [i]);
|
Chris@16
|
2684 #else
|
Chris@16
|
2685 return iterator (*this, i);
|
Chris@16
|
2686 #endif
|
Chris@16
|
2687 }
|
Chris@16
|
2688
|
Chris@16
|
2689 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
2690 class const_iterator:
|
Chris@16
|
2691 public container_const_reference<c_vector>,
|
Chris@16
|
2692 public random_access_iterator_base<dense_random_access_iterator_tag,
|
Chris@16
|
2693 const_iterator, value_type> {
|
Chris@16
|
2694 public:
|
Chris@16
|
2695 typedef typename c_vector::difference_type difference_type;
|
Chris@16
|
2696 typedef typename c_vector::value_type value_type;
|
Chris@16
|
2697 typedef typename c_vector::const_reference reference;
|
Chris@16
|
2698 typedef typename c_vector::const_pointer pointer;
|
Chris@16
|
2699
|
Chris@16
|
2700 // Construction and destruction
|
Chris@16
|
2701 BOOST_UBLAS_INLINE
|
Chris@16
|
2702 const_iterator ():
|
Chris@16
|
2703 container_const_reference<self_type> (), it_ () {}
|
Chris@16
|
2704 BOOST_UBLAS_INLINE
|
Chris@16
|
2705 const_iterator (const self_type &v, const const_subiterator_type &it):
|
Chris@16
|
2706 container_const_reference<self_type> (v), it_ (it) {}
|
Chris@16
|
2707 BOOST_UBLAS_INLINE
|
Chris@16
|
2708 const_iterator (const typename self_type::iterator &it): // ISSUE self_type:: stops VC8 using std::iterator here
|
Chris@16
|
2709 container_const_reference<self_type> (it ()), it_ (it.it_) {}
|
Chris@16
|
2710
|
Chris@16
|
2711 // Arithmetic
|
Chris@16
|
2712 BOOST_UBLAS_INLINE
|
Chris@16
|
2713 const_iterator &operator ++ () {
|
Chris@16
|
2714 ++ it_;
|
Chris@16
|
2715 return *this;
|
Chris@16
|
2716 }
|
Chris@16
|
2717 BOOST_UBLAS_INLINE
|
Chris@16
|
2718 const_iterator &operator -- () {
|
Chris@16
|
2719 -- it_;
|
Chris@16
|
2720 return *this;
|
Chris@16
|
2721 }
|
Chris@16
|
2722 BOOST_UBLAS_INLINE
|
Chris@16
|
2723 const_iterator &operator += (difference_type n) {
|
Chris@16
|
2724 it_ += n;
|
Chris@16
|
2725 return *this;
|
Chris@16
|
2726 }
|
Chris@16
|
2727 BOOST_UBLAS_INLINE
|
Chris@16
|
2728 const_iterator &operator -= (difference_type n) {
|
Chris@16
|
2729 it_ -= n;
|
Chris@16
|
2730 return *this;
|
Chris@16
|
2731 }
|
Chris@16
|
2732 BOOST_UBLAS_INLINE
|
Chris@16
|
2733 difference_type operator - (const const_iterator &it) const {
|
Chris@16
|
2734 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2735 return it_ - it.it_;
|
Chris@16
|
2736 }
|
Chris@16
|
2737
|
Chris@16
|
2738 // Dereference
|
Chris@16
|
2739 BOOST_UBLAS_INLINE
|
Chris@16
|
2740 const_reference operator * () const {
|
Chris@16
|
2741 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
|
Chris@16
|
2742 return *it_;
|
Chris@16
|
2743 }
|
Chris@16
|
2744 BOOST_UBLAS_INLINE
|
Chris@16
|
2745 const_reference operator [] (difference_type n) const {
|
Chris@16
|
2746 return *(it_ + n);
|
Chris@16
|
2747 }
|
Chris@16
|
2748
|
Chris@16
|
2749 // Index
|
Chris@16
|
2750 BOOST_UBLAS_INLINE
|
Chris@16
|
2751 size_type index () const {
|
Chris@16
|
2752 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
|
Chris@16
|
2753 const self_type &v = (*this) ();
|
Chris@16
|
2754 return it_ - v.begin ().it_;
|
Chris@16
|
2755 }
|
Chris@16
|
2756
|
Chris@16
|
2757 // Assignment
|
Chris@16
|
2758 BOOST_UBLAS_INLINE
|
Chris@16
|
2759 const_iterator &operator = (const const_iterator &it) {
|
Chris@16
|
2760 container_const_reference<self_type>::assign (&it ());
|
Chris@16
|
2761 it_ = it.it_;
|
Chris@16
|
2762 return *this;
|
Chris@16
|
2763 }
|
Chris@16
|
2764
|
Chris@16
|
2765 // Comparison
|
Chris@16
|
2766 BOOST_UBLAS_INLINE
|
Chris@16
|
2767 bool operator == (const const_iterator &it) const {
|
Chris@16
|
2768 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2769 return it_ == it.it_;
|
Chris@16
|
2770 }
|
Chris@16
|
2771 BOOST_UBLAS_INLINE
|
Chris@16
|
2772 bool operator < (const const_iterator &it) const {
|
Chris@16
|
2773 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2774 return it_ < it.it_;
|
Chris@16
|
2775 }
|
Chris@16
|
2776
|
Chris@16
|
2777 private:
|
Chris@16
|
2778 const_subiterator_type it_;
|
Chris@16
|
2779
|
Chris@16
|
2780 friend class iterator;
|
Chris@16
|
2781 };
|
Chris@16
|
2782 #endif
|
Chris@16
|
2783
|
Chris@16
|
2784 BOOST_UBLAS_INLINE
|
Chris@16
|
2785 const_iterator begin () const {
|
Chris@16
|
2786 return find (0);
|
Chris@16
|
2787 }
|
Chris@101
|
2788 BOOST_UBLAS_INLINE
|
Chris@101
|
2789 const_iterator cbegin () const {
|
Chris@101
|
2790 return begin ();
|
Chris@101
|
2791 }
|
Chris@16
|
2792 BOOST_UBLAS_INLINE
|
Chris@16
|
2793 const_iterator end () const {
|
Chris@16
|
2794 return find (size_);
|
Chris@16
|
2795 }
|
Chris@101
|
2796 BOOST_UBLAS_INLINE
|
Chris@101
|
2797 const_iterator cend () const {
|
Chris@101
|
2798 return end ();
|
Chris@101
|
2799 }
|
Chris@16
|
2800
|
Chris@16
|
2801 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
|
Chris@16
|
2802 class iterator:
|
Chris@16
|
2803 public container_reference<c_vector>,
|
Chris@16
|
2804 public random_access_iterator_base<dense_random_access_iterator_tag,
|
Chris@16
|
2805 iterator, value_type> {
|
Chris@16
|
2806 public:
|
Chris@16
|
2807 typedef typename c_vector::difference_type difference_type;
|
Chris@16
|
2808 typedef typename c_vector::value_type value_type;
|
Chris@16
|
2809 typedef typename c_vector::reference reference;
|
Chris@16
|
2810 typedef typename c_vector::pointer pointer;
|
Chris@16
|
2811
|
Chris@16
|
2812 // Construction and destruction
|
Chris@16
|
2813 BOOST_UBLAS_INLINE
|
Chris@16
|
2814 iterator ():
|
Chris@16
|
2815 container_reference<self_type> (), it_ () {}
|
Chris@16
|
2816 BOOST_UBLAS_INLINE
|
Chris@16
|
2817 iterator (self_type &v, const subiterator_type &it):
|
Chris@16
|
2818 container_reference<self_type> (v), it_ (it) {}
|
Chris@16
|
2819
|
Chris@16
|
2820 // Arithmetic
|
Chris@16
|
2821 BOOST_UBLAS_INLINE
|
Chris@16
|
2822 iterator &operator ++ () {
|
Chris@16
|
2823 ++ it_;
|
Chris@16
|
2824 return *this;
|
Chris@16
|
2825 }
|
Chris@16
|
2826 BOOST_UBLAS_INLINE
|
Chris@16
|
2827 iterator &operator -- () {
|
Chris@16
|
2828 -- it_;
|
Chris@16
|
2829 return *this;
|
Chris@16
|
2830 }
|
Chris@16
|
2831 BOOST_UBLAS_INLINE
|
Chris@16
|
2832 iterator &operator += (difference_type n) {
|
Chris@16
|
2833 it_ += n;
|
Chris@16
|
2834 return *this;
|
Chris@16
|
2835 }
|
Chris@16
|
2836 BOOST_UBLAS_INLINE
|
Chris@16
|
2837 iterator &operator -= (difference_type n) {
|
Chris@16
|
2838 it_ -= n;
|
Chris@16
|
2839 return *this;
|
Chris@16
|
2840 }
|
Chris@16
|
2841 BOOST_UBLAS_INLINE
|
Chris@16
|
2842 difference_type operator - (const iterator &it) const {
|
Chris@16
|
2843 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2844 return it_ - it.it_;
|
Chris@16
|
2845 }
|
Chris@16
|
2846
|
Chris@16
|
2847 // Dereference
|
Chris@16
|
2848 BOOST_UBLAS_INLINE
|
Chris@16
|
2849 reference operator * () const {
|
Chris@16
|
2850 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
|
Chris@16
|
2851 return *it_;
|
Chris@16
|
2852 }
|
Chris@16
|
2853 BOOST_UBLAS_INLINE
|
Chris@16
|
2854 reference operator [] (difference_type n) const {
|
Chris@16
|
2855 return *(it_ + n);
|
Chris@16
|
2856 }
|
Chris@16
|
2857
|
Chris@16
|
2858 // Index
|
Chris@16
|
2859 BOOST_UBLAS_INLINE
|
Chris@16
|
2860 size_type index () const {
|
Chris@16
|
2861 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
|
Chris@16
|
2862 // EDG won't allow const self_type it doesn't allow friend access to it_
|
Chris@16
|
2863 self_type &v = (*this) ();
|
Chris@16
|
2864 return it_ - v.begin ().it_;
|
Chris@16
|
2865 }
|
Chris@16
|
2866
|
Chris@16
|
2867 // Assignment
|
Chris@16
|
2868 BOOST_UBLAS_INLINE
|
Chris@16
|
2869 iterator &operator = (const iterator &it) {
|
Chris@16
|
2870 container_reference<self_type>::assign (&it ());
|
Chris@16
|
2871 it_ = it.it_;
|
Chris@16
|
2872 return *this;
|
Chris@16
|
2873 }
|
Chris@16
|
2874
|
Chris@16
|
2875 // Comparison
|
Chris@16
|
2876 BOOST_UBLAS_INLINE
|
Chris@16
|
2877 bool operator == (const iterator &it) const {
|
Chris@16
|
2878 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2879 return it_ == it.it_;
|
Chris@16
|
2880 }
|
Chris@16
|
2881 BOOST_UBLAS_INLINE
|
Chris@16
|
2882 bool operator < (const iterator &it) const {
|
Chris@16
|
2883 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
|
Chris@16
|
2884 return it_ < it.it_;
|
Chris@16
|
2885 }
|
Chris@16
|
2886
|
Chris@16
|
2887 private:
|
Chris@16
|
2888 subiterator_type it_;
|
Chris@16
|
2889
|
Chris@16
|
2890 friend class const_iterator;
|
Chris@16
|
2891 };
|
Chris@16
|
2892 #endif
|
Chris@16
|
2893
|
Chris@16
|
2894 BOOST_UBLAS_INLINE
|
Chris@16
|
2895 iterator begin () {
|
Chris@16
|
2896 return find (0);
|
Chris@16
|
2897 }
|
Chris@16
|
2898 BOOST_UBLAS_INLINE
|
Chris@16
|
2899 iterator end () {
|
Chris@16
|
2900 return find (size_);
|
Chris@16
|
2901 }
|
Chris@16
|
2902
|
Chris@16
|
2903 // Reverse iterator
|
Chris@16
|
2904 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
|
Chris@16
|
2905 typedef reverse_iterator_base<iterator> reverse_iterator;
|
Chris@16
|
2906
|
Chris@16
|
2907 BOOST_UBLAS_INLINE
|
Chris@16
|
2908 const_reverse_iterator rbegin () const {
|
Chris@16
|
2909 return const_reverse_iterator (end ());
|
Chris@16
|
2910 }
|
Chris@101
|
2911 BOOST_UBLAS_INLINE
|
Chris@101
|
2912 const_reverse_iterator crbegin () const {
|
Chris@101
|
2913 return rbegin ();
|
Chris@101
|
2914 }
|
Chris@16
|
2915 BOOST_UBLAS_INLINE
|
Chris@16
|
2916 const_reverse_iterator rend () const {
|
Chris@16
|
2917 return const_reverse_iterator (begin ());
|
Chris@16
|
2918 }
|
Chris@101
|
2919 BOOST_UBLAS_INLINE
|
Chris@101
|
2920 const_reverse_iterator crend () const {
|
Chris@101
|
2921 return rend ();
|
Chris@101
|
2922 }
|
Chris@16
|
2923 BOOST_UBLAS_INLINE
|
Chris@16
|
2924 reverse_iterator rbegin () {
|
Chris@16
|
2925 return reverse_iterator (end ());
|
Chris@16
|
2926 }
|
Chris@16
|
2927 BOOST_UBLAS_INLINE
|
Chris@16
|
2928 reverse_iterator rend () {
|
Chris@16
|
2929 return reverse_iterator (begin ());
|
Chris@16
|
2930 }
|
Chris@16
|
2931
|
Chris@16
|
2932 // Serialization
|
Chris@16
|
2933 template<class Archive>
|
Chris@16
|
2934 void serialize(Archive & ar, const unsigned int /* file_version */){
|
Chris@16
|
2935 serialization::collection_size_type s (size_);
|
Chris@16
|
2936 ar & serialization::make_nvp("size",s);
|
Chris@16
|
2937
|
Chris@16
|
2938 // copy the value back if loading
|
Chris@16
|
2939 if (Archive::is_loading::value) {
|
Chris@16
|
2940 if (s > N) bad_size("too large size in bounded_vector::load()\n").raise();
|
Chris@16
|
2941 size_ = s;
|
Chris@16
|
2942 }
|
Chris@16
|
2943 // ISSUE: this writes the full array
|
Chris@16
|
2944 ar & serialization::make_nvp("data",data_);
|
Chris@16
|
2945 }
|
Chris@16
|
2946
|
Chris@16
|
2947 private:
|
Chris@16
|
2948 size_type size_;
|
Chris@16
|
2949 array_type data_;
|
Chris@16
|
2950 };
|
Chris@16
|
2951
|
Chris@16
|
2952 }}}
|
Chris@16
|
2953
|
Chris@16
|
2954 #endif
|