ndarray
NumPy-friendly multidimensional arrays in C++
Loading...
Searching...
No Matches
Vector.h
Go to the documentation of this file.
1// -*- c++ -*-
2/*
3 * Copyright (c) 2010-2012, Jim Bosch
4 * All rights reserved.
5 *
6 * ndarray is distributed under a simple BSD-like license;
7 * see the LICENSE file that should be present in the root
8 * of the source distribution, or alternately available at:
9 * https://github.com/ndarray/ndarray
10 */
11
12#ifndef NDARRAY_Vector_h_INCLUDED
13#define NDARRAY_Vector_h_INCLUDED
14
16
17#include <boost/type_traits/is_arithmetic.hpp>
18#include <boost/iterator/reverse_iterator.hpp>
19#include <boost/utility/enable_if.hpp>
20#include <boost/mpl/int.hpp>
21#include <boost/preprocessor/repetition/repeat.hpp>
22#include <boost/preprocessor/repetition/repeat_from_to.hpp>
23#include <boost/preprocessor/repetition/enum.hpp>
24
25#include <iostream>
26
27#include "ndarray_fwd.h"
28#include "ndarray/types.h"
29
31#define NDARRAY_MAKE_VECTOR_MAX 8
32
33#define NDARRAY_MAKE_VECTOR_ARG_SPEC(Z,I,DATA) T v ## I
34#define NDARRAY_MAKE_VECTOR_SET_SPEC(Z,I,DATA) r[I] = v ## I;
35
36#define NDARRAY_MAKE_VECTOR_SPEC(Z,N,DATA) \
37 template <typename T> \
38 inline Vector<T,N> makeVector( \
39 BOOST_PP_ENUM(N,NDARRAY_MAKE_VECTOR_ARG_SPEC,unused) \
40 ) { \
41 Vector<T,N> r; \
42 BOOST_PP_REPEAT(N,NDARRAY_MAKE_VECTOR_SET_SPEC,unused) \
43 return r; \
44 }
45
47
48namespace ndarray {
49
50namespace detail {
51
52template <typename T, bool isArithmetic=boost::is_arithmetic<T>::value>
54 static T get() { return T(); }
55};
56
57template <typename T>
58struct DefaultValue<T,true> {
59 static T get() { return T(0); }
60};
61
62} // namespace detail
63
66
78template <
79 typename T,
80 int N
81 >
82struct Vector {
83
84 typedef T Element;
85 typedef T Value;
86 typedef T & Reference;
87 typedef T const & ConstReference;
88 typedef T * Iterator;
89 typedef T const * ConstIterator;
90
91 typedef Value value_type;
92 typedef Iterator iterator;
93 typedef ConstIterator const_iterator;
94 typedef Reference reference;
95 typedef ConstReference const_reference;
96 typedef boost::reverse_iterator<T*> reverse_iterator;
97 typedef boost::reverse_iterator<const T*> const_reverse_iterator;
98 typedef T * pointer;
99 typedef int difference_type;
100 typedef int size_type;
101
102
103 typedef boost::mpl::int_<N> ND;
105 size_type size() const { return N; }
107 size_type max_size() const { return N; }
109 bool empty() const { return N==0; }
111 iterator begin() { return elems; }
113 const_iterator begin() const { return elems; }
115 iterator end() { return elems+N; }
117 const_iterator end() const { return elems+N; }
119 reverse_iterator rbegin() { return reverse_iterator(end()); }
121 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
123 reverse_iterator rend() { return reverse_iterator(begin()); }
125 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
126
128 reference front() { return *elems; }
130 reference back() { return *(elems+N-1); }
132 const_reference front() const { return *elems; }
134 const_reference back() const { return *(elems+N-1); }
135
137 reference operator[](int i) { return elems[i]; }
139 const_reference operator[](int i) const { return elems[i]; }
140
142 template <int Start, int Stop>
143 Vector<T,Stop-Start> getRange() const {
144 Vector<T,Stop-Start> r;
145 std::copy(begin() + Start, begin()+Stop, r.begin());
146 return r;
147 }
148
150 template <int M> Vector<T,M> first() const {
151 Vector<T,M> r;
152 std::copy(begin(), begin() + M, r.begin());
153 return r;
154 }
155
157 template <int M> Vector<T,M> last() const {
158 Vector<T,M> r;
159 std::copy(begin() + (N - M), begin() + N, r.begin());
160 return r;
161 }
162
164 friend std::ostream& operator<<(std::ostream& os, Vector<T,N> const & obj) {
165 os << "(";
166 std::copy(obj.begin(), obj.end(), std::ostream_iterator<T>(os,","));
167 return os << ")";
168 }
169
175 Vector() { this->
176 #ifndef _MSC_VER
177 template
178 #endif
180
182 explicit Vector(T scalar) {
183 this->operator=(scalar);
184 }
185
187 template <typename U>
188 Vector(Vector<U,N> const & other) {
189 this->
190 #ifndef _MSC_VER
191 template
192 #endif
193 operator=(other);
194 }
195
197 bool operator==(Vector const & other) const {
198 return std::equal(begin(), end(), other.begin());
199 }
200
202 bool operator!=(Vector const & other) const {
203 return !(*this == other);
204 }
205
207 T sum() const {
208 T r = 0;
209 for (ConstIterator i = begin(); i != end(); ++i) r += (*i);
210 return r;
211 }
212
214 T product() const {
215 T r = 1;
216 for (ConstIterator i = begin(); i != end(); ++i) r *= (*i);
217 return r;
218 }
219
221 Vector reverse() const {
222 Vector r;
223 std::copy(begin(), end(), r.rbegin());
224 return r;
225 }
226
228 template <typename U>
230 Vector<U,N> r;
231 for (int i = 0; i < N; ++i) {
232 r[i] = static_cast<U>((*this)[i]);
233 }
234 return r;
235 }
236
237
239 template <typename U>
240 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
241 operator = (Vector<U,N> const & other) {
242 typename Vector<U,N>::ConstIterator j = other.begin();
243 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) = (*j);
244 return *this;
245 }
247 template <typename U>
248 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
249 operator = (U scalar) {
250 for (Iterator i = begin(); i != end(); ++i) (*i) = scalar;
251 return *this;
252 }
253
255 template <typename U>
256 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
257 operator += (Vector<U,N> const & other) {
258 typename Vector<U,N>::ConstIterator j = other.begin();
259 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) += (*j);
260 return *this;
261 }
263 template <typename U>
264 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
265 operator += (U scalar) {
266 for (Iterator i = begin(); i != end(); ++i) (*i) += scalar;
267 return *this;
268 }
269
271 template <typename U>
272 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
273 operator -= (Vector<U,N> const & other) {
274 typename Vector<U,N>::ConstIterator j = other.begin();
275 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) -= (*j);
276 return *this;
277 }
279 template <typename U>
280 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
281 operator -= (U scalar) {
282 for (Iterator i = begin(); i != end(); ++i) (*i) -= scalar;
283 return *this;
284 }
285
287 template <typename U>
288 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
289 operator *= (Vector<U,N> const & other) {
290 typename Vector<U,N>::ConstIterator j = other.begin();
291 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) *= (*j);
292 return *this;
293 }
295 template <typename U>
296 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
297 operator *= (U scalar) {
298 for (Iterator i = begin(); i != end(); ++i) (*i) *= scalar;
299 return *this;
300 }
301
303 template <typename U>
304 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
305 operator /= (Vector<U,N> const & other) {
306 typename Vector<U,N>::ConstIterator j = other.begin();
307 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) /= (*j);
308 return *this;
309 }
311 template <typename U>
312 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
313 operator /= (U scalar) {
314 for (Iterator i = begin(); i != end(); ++i) (*i) /= scalar;
315 return *this;
316 }
317
319 template <typename U>
320 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
321 operator %= (Vector<U,N> const & other) {
322 typename Vector<U,N>::ConstIterator j = other.begin();
323 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) %= (*j);
324 return *this;
325 }
327 template <typename U>
328 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
329 operator %= (U scalar) {
330 for (Iterator i = begin(); i != end(); ++i) (*i) %= scalar;
331 return *this;
332 }
333
335 template <typename U>
336 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
337 operator &= (Vector<U,N> const & other) {
338 typename Vector<U,N>::ConstIterator j = other.begin();
339 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) &= (*j);
340 return *this;
341 }
343 template <typename U>
344 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
345 operator &= (U scalar) {
346 for (Iterator i = begin(); i != end(); ++i) (*i) &= scalar;
347 return *this;
348 }
349
351 template <typename U>
352 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
353 operator ^= (Vector<U,N> const & other) {
354 typename Vector<U,N>::ConstIterator j = other.begin();
355 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) ^= (*j);
356 return *this;
357 }
359 template <typename U>
360 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
361 operator ^= (U scalar) {
362 for (Iterator i = begin(); i != end(); ++i) (*i) ^= scalar;
363 return *this;
364 }
365
367 template <typename U>
368 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
369 operator |= (Vector<U,N> const & other) {
370 typename Vector<U,N>::ConstIterator j = other.begin();
371 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) |= (*j);
372 return *this;
373 }
375 template <typename U>
376 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
377 operator |= (U scalar) {
378 for (Iterator i = begin(); i != end(); ++i) (*i) |= scalar;
379 return *this;
380 }
381
383 template <typename U>
384 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
385 operator <<= (Vector<U,N> const & other) {
386 typename Vector<U,N>::ConstIterator j = other.begin();
387 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) <<= (*j);
388 return *this;
389 }
391 template <typename U>
392 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
393 operator <<= (U scalar) {
394 for (Iterator i = begin(); i != end(); ++i) (*i) <<= scalar;
395 return *this;
396 }
397
399 template <typename U>
400 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
401 operator >>= (Vector<U,N> const & other) {
402 typename Vector<U,N>::ConstIterator j = other.begin();
403 for (Iterator i = begin(); i != end(); ++i, ++j) (*i) >>= (*j);
404 return *this;
405 }
407 template <typename U>
408 typename boost::enable_if<boost::is_convertible<U,T>,Vector&>::type
409 operator >>= (U scalar) {
410 for (Iterator i = begin(); i != end(); ++i) (*i) >>= scalar;
411 return *this;
412 }
413
414 T elems[N];
415};
416
418template <typename T>
419struct Vector<T,0> {
420
421 typedef T Element;
422 typedef T Value;
423 typedef T & Reference;
424 typedef T const & ConstReference;
425 typedef T * Iterator;
426 typedef T const * ConstIterator;
427
428 typedef Value value_type;
429 typedef Iterator iterator;
430 typedef ConstIterator const_iterator;
431 typedef Reference reference;
432 typedef ConstReference const_reference;
433 typedef boost::reverse_iterator<T*> reverse_iterator;
434 typedef boost::reverse_iterator<const T*> const_reverse_iterator;
435 typedef T * pointer;
436 typedef int difference_type;
437 typedef int size_type;
438
439
440 typedef boost::mpl::int_<0> ND;
441
442 size_type size() const { return 0; }
443 size_type max_size() const { return 0; }
444 bool empty() const { return true; }
446 iterator begin() { return 0; }
448 const_iterator begin() const { return 0; }
450 iterator end() { return 0; }
452 const_iterator end() const { return 0; }
454 reverse_iterator rbegin() { return reverse_iterator(); }
456 const_reverse_iterator rbegin() const { return const_reverse_iterator(); }
458 reverse_iterator rend() { return reverse_iterator(); }
460 const_reverse_iterator rend() const { return const_reverse_iterator(); }
461
463 reference front() { NDARRAY_ASSERT(false); return 0; }
465 reference back() { return NDARRAY_ASSERT(false); return 0; }
467 const_reference front() const { NDARRAY_ASSERT(false); return 0; }
469 const_reference back() const { NDARRAY_ASSERT(false); return 0; }
470
472 reference operator[](int i) { NDARRAY_ASSERT(false); return 0; }
474 const_reference operator[](int i) const { NDARRAY_ASSERT(false); return 0; }
475
477 template <int Start, int Stop>
478 Vector<T,Stop-Start> getRange() const {
479 return Vector<T,Stop-Start>();
480 }
481
483 template <int M> Vector<T,M> first() const {
484 return Vector<T,M>();
485 }
486
488 template <int M> Vector<T,M> last() const {
489 return Vector<T,M>();
490 }
491
493 friend std::ostream& operator<<(std::ostream& os, Vector<T,0> const & obj) {
494 return os << "()";
495 }
496
503
505 explicit Vector(T scalar) {}
506
508 template <typename U>
509 Vector(Vector<U,0> const & other) {}
510
512 bool operator==(Vector const & other) const { return true; }
513
515 bool operator!=(Vector const & other) const { return false; }
516
518 T sum() const { return 0; }
519
521 T product() const { return 1; }
522
524 Vector reverse() const { return Vector(); }
525
527 template <typename U>
528 Vector<U,0> cast() const { return Vector<U,0>(); }
529
530};
531
532
534template <typename T, int N, int M>
535inline Vector<T,N+M> concatenate(Vector<T,N> const & a, Vector<T,M> const & b) {
537 std::copy(a.begin(),a.end(),r.begin());
538 std::copy(b.begin(),b.end(),r.begin()+N);
539 return r;
540}
541
543template <typename T, int N, typename U>
544inline typename boost::enable_if<boost::is_convertible<U,T>,Vector<T,N+1> >::type
545concatenate(Vector<T,N> const & a, U b) {
547 std::copy(a.begin(),a.end(),r.begin());
548 r[N] = b;
549 return r;
550}
551
553template <typename T, int N, typename U>
554inline typename boost::enable_if<boost::is_convertible<U,T>,Vector<T,N+1> >::type
555concatenate(U a, Vector<T,N> const & b) {
557 r[0] = a;
558 std::copy(b.begin(),b.end(),r.begin()+1);
559 return r;
560}
561
562#ifndef DOXYGEN
563BOOST_PP_REPEAT_FROM_TO(1, NDARRAY_MAKE_VECTOR_MAX, NDARRAY_MAKE_VECTOR_SPEC, unused)
564#else
570template <typename T, int N>
571Vector<T,N> makeVector(T v1, T v2, ..., T vN);
572#endif
573
575template <typename T, int N>
576inline Vector<T,N> operator~(Vector<T,N> const & vector) {
577 Vector<T,N> r(vector);
578 for (typename Vector<T,N>::Iterator i = r.begin(); i != r.end(); ++i) (*i) = ~(*i);
579 return r;
580}
581
583template <typename T, int N>
584inline Vector<T,N> operator!(Vector<T,N> const & vector) {
585 Vector<T,N> r(vector);
586 for (typename Vector<T,N>::Iterator i = r.begin(); i != r.end(); ++i) (*i) = !(*i);
587 return r;
588}
589
590
592 template <typename T, typename U, int N>
593 Vector<typename Promote<T,U>::Type,N>
594 operator +(Vector<T,N> const & a, Vector<U,N> const & b) {
596 return r += b;
597 }
599 template <typename T, typename U, int N>
600 Vector<typename Promote<T,U>::Type,N>
601 operator +(Vector<T,N> const & a, U b) {
603 return r += b;
604 }
606 template <typename T, typename U, int N>
607 Vector<typename Promote<T,U>::Type,N>
608 operator +(U a, Vector<T,N> const & b) {
610 return r += b;
611 }
612
614 template <typename T, typename U, int N>
615 Vector<typename Promote<T,U>::Type,N>
616 operator -(Vector<T,N> const & a, Vector<U,N> const & b) {
618 return r -= b;
619 }
621 template <typename T, typename U, int N>
622 Vector<typename Promote<T,U>::Type,N>
623 operator -(Vector<T,N> const & a, U b) {
625 return r -= b;
626 }
628 template <typename T, typename U, int N>
629 Vector<typename Promote<T,U>::Type,N>
630 operator -(U a, Vector<T,N> const & b) {
632 return r -= b;
633 }
634
636 template <typename T, typename U, int N>
637 Vector<typename Promote<T,U>::Type,N>
638 operator *(Vector<T,N> const & a, Vector<U,N> const & b) {
640 return r *= b;
641 }
643 template <typename T, typename U, int N>
644 Vector<typename Promote<T,U>::Type,N>
645 operator *(Vector<T,N> const & a, U b) {
647 return r *= b;
648 }
650 template <typename T, typename U, int N>
651 Vector<typename Promote<T,U>::Type,N>
652 operator *(U a, Vector<T,N> const & b) {
654 return r *= b;
655 }
656
658 template <typename T, typename U, int N>
659 Vector<typename Promote<T,U>::Type,N>
660 operator /(Vector<T,N> const & a, Vector<U,N> const & b) {
662 return r /= b;
663 }
665 template <typename T, typename U, int N>
666 Vector<typename Promote<T,U>::Type,N>
667 operator /(Vector<T,N> const & a, U b) {
669 return r /= b;
670 }
672 template <typename T, typename U, int N>
673 Vector<typename Promote<T,U>::Type,N>
674 operator /(U a, Vector<T,N> const & b) {
676 return r /= b;
677 }
678
680 template <typename T, typename U, int N>
681 Vector<typename Promote<T,U>::Type,N>
682 operator %(Vector<T,N> const & a, Vector<U,N> const & b) {
684 return r %= b;
685 }
687 template <typename T, typename U, int N>
688 Vector<typename Promote<T,U>::Type,N>
689 operator %(Vector<T,N> const & a, U b) {
691 return r %= b;
692 }
694 template <typename T, typename U, int N>
695 Vector<typename Promote<T,U>::Type,N>
696 operator %(U a, Vector<T,N> const & b) {
698 return r %= b;
699 }
700
702 template <typename T, typename U, int N>
703 Vector<typename Promote<T,U>::Type,N>
704 operator &(Vector<T,N> const & a, Vector<U,N> const & b) {
706 return r &= b;
707 }
709 template <typename T, typename U, int N>
710 Vector<typename Promote<T,U>::Type,N>
711 operator &(Vector<T,N> const & a, U b) {
713 return r &= b;
714 }
716 template <typename T, typename U, int N>
717 Vector<typename Promote<T,U>::Type,N>
718 operator &(U a, Vector<T,N> const & b) {
720 return r &= b;
721 }
722
724 template <typename T, typename U, int N>
725 Vector<typename Promote<T,U>::Type,N>
726 operator ^(Vector<T,N> const & a, Vector<U,N> const & b) {
728 return r ^= b;
729 }
731 template <typename T, typename U, int N>
732 Vector<typename Promote<T,U>::Type,N>
733 operator ^(Vector<T,N> const & a, U b) {
735 return r ^= b;
736 }
738 template <typename T, typename U, int N>
739 Vector<typename Promote<T,U>::Type,N>
740 operator ^(U a, Vector<T,N> const & b) {
742 return r ^= b;
743 }
744
746 template <typename T, typename U, int N>
747 Vector<typename Promote<T,U>::Type,N>
748 operator |(Vector<T,N> const & a, Vector<U,N> const & b) {
750 return r |= b;
751 }
753 template <typename T, typename U, int N>
754 Vector<typename Promote<T,U>::Type,N>
755 operator |(Vector<T,N> const & a, U b) {
757 return r |= b;
758 }
760 template <typename T, typename U, int N>
761 Vector<typename Promote<T,U>::Type,N>
762 operator |(U a, Vector<T,N> const & b) {
764 return r |= b;
765 }
766
768 template <typename T, typename U, int N>
769 Vector<typename Promote<T,U>::Type,N>
770 operator <<(Vector<T,N> const & a, Vector<U,N> const & b) {
771 Vector<typename Promote<T,U>::Type,N> r(a);
772 return r <<= b;
773 }
775 template <typename T, typename U, int N>
776 Vector<typename Promote<T,U>::Type,N>
777 operator <<(Vector<T,N> const & a, U b) {
778 Vector<typename Promote<T,U>::Type,N> r(a);
779 return r <<= b;
780 }
782 template <typename T, typename U, int N>
783 Vector<typename Promote<T,U>::Type,N>
784 operator <<(U a, Vector<T,N> const & b) {
785 Vector<typename Promote<T,U>::Type,N> r(a);
786 return r <<= b;
787 }
788
790 template <typename T, typename U, int N>
791 Vector<typename Promote<T,U>::Type,N>
792 operator >>(Vector<T,N> const & a, Vector<U,N> const & b) {
794 return r >>= b;
795 }
797 template <typename T, typename U, int N>
798 Vector<typename Promote<T,U>::Type,N>
799 operator >>(Vector<T,N> const & a, U b) {
801 return r >>= b;
802 }
804 template <typename T, typename U, int N>
805 Vector<typename Promote<T,U>::Type,N>
806 operator >>(U a, Vector<T,N> const & b) {
808 return r >>= b;
809 }
810
812
813} // namespace ndarray
814
815#endif // !NDARRAY_Vector_h_INCLUDED
Vector< T, N > operator!(Vector< T, N > const &vector)
Unary negation for Vector.
Definition Vector.h:584
Vector< T, N+M > concatenate(Vector< T, N > const &a, Vector< T, M > const &b)
Concatenate two Vectors into a single long Vector.
Definition Vector.h:535
Forward declarations and default template parameters for ndarray.
size_type max_size() const
Return the size of the Vector.
Definition Vector.h:443
reverse_iterator rbegin()
Return a reverse_iterator to the beginning of the reversed Vector.
Definition Vector.h:454
Vector< U, 0 > cast() const
Cast the vector element-wise to another type.
Definition Vector.h:528
Vector reverse() const
Return a Vector with the elements reversed.
Definition Vector.h:524
const_reverse_iterator rbegin() const
Return a const_reverse_iterator to the beginning of the reversed Vector.
Definition Vector.h:456
const_reverse_iterator rend() const
Return a const_reverse_iterator to the end of the reversed Vector.
Definition Vector.h:460
Vector< T, M > first() const
Create a new Vector from the first M elements of this.
Definition Vector.h:483
bool empty() const
Return true if size() == 0.
Definition Vector.h:444
reference operator[](int i)
Return a reference to the element with the given index.
Definition Vector.h:472
Vector()
Default constructor.
Definition Vector.h:502
size_type size() const
Return the size of the Vector.
Definition Vector.h:442
iterator begin()
Return an iterator to the beginning of the Vector.
Definition Vector.h:446
T product() const
Return the product of all elements.
Definition Vector.h:521
friend std::ostream & operator<<(std::ostream &os, Vector< T, 0 > const &obj)
Stream output.
Definition Vector.h:493
const_reference back() const
Return a const_reference to the last element.
Definition Vector.h:469
const_reference operator[](int i) const
Return a const_reference to the element with the given index.
Definition Vector.h:474
reference front()
Return a reference to the first element.
Definition Vector.h:463
T sum() const
Return the sum of all elements.
Definition Vector.h:518
const_iterator end() const
Return a const_iterator to the end of the Vector.
Definition Vector.h:452
Vector(T scalar)
Construct with copies of a scalar.
Definition Vector.h:505
reverse_iterator rend()
Return a reverse_iterator to the end of the reversed Vector.
Definition Vector.h:458
Vector(Vector< U, 0 > const &other)
Converting copy constructor.
Definition Vector.h:509
Vector< T, M > last() const
Create a new Vector from the last M elements of this.
Definition Vector.h:488
const_reference front() const
Return a const_reference to the first element.
Definition Vector.h:467
bool operator!=(Vector const &other) const
Return false if any elements of other are not equal to the elements of this.
Definition Vector.h:515
const_iterator begin() const
Return a const_iterator to the beginning of the Vector.
Definition Vector.h:448
Vector< T, Stop-Start > getRange() const
Create a new Vector that is a subset of this.
Definition Vector.h:478
reference back()
Return a reference to the last element.
Definition Vector.h:465
iterator end()
Return an iterator to the end of the Vector.
Definition Vector.h:450
bool operator==(Vector const &other) const
Return true if elements of other are equal to the elements of this.
Definition Vector.h:512
A fixed-size 1D array class.
Definition Vector.h:82
Vector(T scalar)
Construct with copies of a scalar.
Definition Vector.h:182
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator+=(Vector< U, N > const &other)
Augmented += assignment from another vector.
Definition Vector.h:257
Vector< T, M > first() const
Create a new Vector from the first M elements of this.
Definition Vector.h:150
reverse_iterator rend()
Return a reverse_iterator to the end of the reversed Vector.
Definition Vector.h:123
friend std::ostream & operator<<(std::ostream &os, Vector< T, N > const &obj)
Stream output.
Definition Vector.h:164
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator/=(Vector< U, N > const &other)
Augmented /= assignment from another vector.
Definition Vector.h:305
Vector()
Default constructor.
Definition Vector.h:175
T product() const
Return the product of all elements.
Definition Vector.h:214
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator|=(Vector< U, N > const &other)
Augmented |= assignment from another vector.
Definition Vector.h:369
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator%=(Vector< U, N > const &other)
Augmented %= assignment from another vector.
Definition Vector.h:321
T sum() const
Return the sum of all elements.
Definition Vector.h:207
iterator begin()
Return an iterator to the beginning of the Vector.
Definition Vector.h:111
const_reverse_iterator rbegin() const
Return a const_reverse_iterator to the beginning of the reversed Vector.
Definition Vector.h:121
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator*=(Vector< U, N > const &other)
Augmented *= assignment from another vector.
Definition Vector.h:289
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator&=(Vector< U, N > const &other)
Augmented &= assignment from another vector.
Definition Vector.h:337
Vector< T, Stop-Start > getRange() const
Create a new Vector that is a subset of this.
Definition Vector.h:143
const_reference operator[](int i) const
Return a const_reference to the element with the given index.
Definition Vector.h:139
Vector(Vector< U, N > const &other)
Converting copy constructor.
Definition Vector.h:188
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator<<=(Vector< U, N > const &other)
Augmented <<= assignment from another vector.
Definition Vector.h:385
bool operator!=(Vector const &other) const
Return false if any elements of other are not equal to the elements of this.
Definition Vector.h:202
reference operator[](int i)
Return a reference to the element with the given index.
Definition Vector.h:137
const_iterator begin() const
Return a const_iterator to the beginning of the Vector.
Definition Vector.h:113
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator>>=(Vector< U, N > const &other)
Augmented >>= assignment from another vector.
Definition Vector.h:401
Vector reverse() const
Return a Vector with the elements reversed.
Definition Vector.h:221
Vector< T, M > last() const
Create a new Vector from the last M elements of this.
Definition Vector.h:157
const_reference back() const
Return a const_reference to the last element.
Definition Vector.h:134
size_type size() const
Return the size of the Vector.
Definition Vector.h:105
const_iterator end() const
Return a const_iterator to the end of the Vector.
Definition Vector.h:117
size_type max_size() const
Return the size of the Vector.
Definition Vector.h:107
const_reverse_iterator rend() const
Return a const_reverse_iterator to the end of the reversed Vector.
Definition Vector.h:125
reverse_iterator rbegin()
Return a reverse_iterator to the beginning of the reversed Vector.
Definition Vector.h:119
reference back()
Return a reference to the last element.
Definition Vector.h:130
bool operator==(Vector const &other) const
Return true if elements of other are equal to the elements of this.
Definition Vector.h:197
iterator end()
Return an iterator to the end of the Vector.
Definition Vector.h:115
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator=(Vector< U, N > const &other)
Augmented = assignment from another vector.
Definition Vector.h:241
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator^=(Vector< U, N > const &other)
Augmented ^= assignment from another vector.
Definition Vector.h:353
Vector< U, N > cast() const
Cast the vector element-wise to another type.
Definition Vector.h:229
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator-=(Vector< U, N > const &other)
Augmented -= assignment from another vector.
Definition Vector.h:273
reference front()
Return a reference to the first element.
Definition Vector.h:128
const_reference front() const
Return a const_reference to the first element.
Definition Vector.h:132
Definition Vector.h:53
Numeric type traits.