23 #ifndef NDARRAY_Vector_h_INCLUDED
24 #define NDARRAY_Vector_h_INCLUDED
28 #include <boost/type_traits/is_arithmetic.hpp>
29 #include <boost/iterator/reverse_iterator.hpp>
30 #include <boost/mpl/int.hpp>
31 #include <boost/utility/enable_if.hpp>
32 #include <boost/preprocessor/repetition/repeat.hpp>
33 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
34 #include <boost/preprocessor/repetition/enum.hpp>
42 #define NDARRAY_MAKE_VECTOR_MAX 8
44 #define NDARRAY_MAKE_VECTOR_ARG_SPEC(Z,I,DATA) T v ## I
45 #define NDARRAY_MAKE_VECTOR_SET_SPEC(Z,I,DATA) r[I] = v ## I;
47 #define NDARRAY_MAKE_VECTOR_SPEC(Z,N,DATA) \
48 template <typename T> \
49 inline Vector<T,N> makeVector( \
50 BOOST_PP_ENUM(N,NDARRAY_MAKE_VECTOR_ARG_SPEC,unused) \
53 BOOST_PP_REPEAT(N,NDARRAY_MAKE_VECTOR_SET_SPEC,unused) \
63 template <typename T, bool isArithmetic=boost::is_arithmetic<T>::value>
65 static T
get() {
return T(); }
70 static T
get() {
return T(0); }
114 typedef boost::mpl::int_<N>
ND;
151 template <
int Start,
int Stop>
173 friend std::ostream& operator<<(std::ostream& os, Vector<T,N>
const & obj) {
175 std::copy(obj.begin(), obj.end(), std::ostream_iterator<T>(os,
","));
187 template <
typename U>
193 template <
typename U>
205 return !(*
this == other);
231 template <
typename U>
232 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
239 template <
typename U>
240 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
247 template <
typename U>
248 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
255 template <
typename U>
256 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
263 template <
typename U>
264 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
271 template <
typename U>
272 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
279 template <
typename U>
280 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
287 template <
typename U>
288 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
295 template <
typename U>
296 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
303 template <
typename U>
304 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
311 template <
typename U>
312 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
319 template <
typename U>
320 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
327 template <
typename U>
328 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
335 template <
typename U>
336 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
343 template <
typename U>
344 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
351 template <
typename U>
352 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
359 template <
typename U>
360 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
367 template <
typename U>
368 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
375 template <
typename U>
376 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
377 operator <<= (Vector<U,N>
const & other) {
383 template <
typename U>
384 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
391 template <
typename U>
392 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
399 template <
typename U>
400 typename boost::enable_if<boost::is_convertible<U,T>,
Vector&>::type
410 template <
typename T>
432 typedef boost::mpl::int_<0>
ND;
469 template <
int Start,
int Stop>
471 return Vector<T,Stop-Start>();
485 friend std::ostream& operator<<(std::ostream& os, Vector<T,0>
const & obj) {
497 template <
typename U>
501 template <
typename U>
511 T
sum()
const {
return 0; }
523 template <
typename T,
int N,
int M>
532 template <
typename T,
int N>
541 template <
typename T,
int N>
550 BOOST_PP_REPEAT_FROM_TO(1, NDARRAY_MAKE_VECTOR_MAX, NDARRAY_MAKE_VECTOR_SPEC, unused)
557 template <
typename T,
int N>
558 Vector<T,N>
makeVector(T v1, T v2, ..., T vN);
562 template <
typename T,
int N>
570 template <
typename T,
int N>
579 template <
typename T,
typename U,
int N>
580 Vector<typename Promote<T,U>::Type,N>
586 template <
typename T,
typename U,
int N>
587 Vector<typename Promote<T,U>::Type,N>
593 template <
typename T,
typename U,
int N>
594 Vector<typename Promote<T,U>::Type,N>
601 template <
typename T,
typename U,
int N>
602 Vector<typename Promote<T,U>::Type,N>
608 template <
typename T,
typename U,
int N>
609 Vector<typename Promote<T,U>::Type,N>
615 template <
typename T,
typename U,
int N>
616 Vector<typename Promote<T,U>::Type,N>
623 template <
typename T,
typename U,
int N>
624 Vector<typename Promote<T,U>::Type,N>
630 template <
typename T,
typename U,
int N>
631 Vector<typename Promote<T,U>::Type,N>
637 template <
typename T,
typename U,
int N>
638 Vector<typename Promote<T,U>::Type,N>
645 template <
typename T,
typename U,
int N>
646 Vector<typename Promote<T,U>::Type,N>
652 template <
typename T,
typename U,
int N>
653 Vector<typename Promote<T,U>::Type,N>
659 template <
typename T,
typename U,
int N>
660 Vector<typename Promote<T,U>::Type,N>
667 template <
typename T,
typename U,
int N>
668 Vector<typename Promote<T,U>::Type,N>
674 template <
typename T,
typename U,
int N>
675 Vector<typename Promote<T,U>::Type,N>
681 template <
typename T,
typename U,
int N>
682 Vector<typename Promote<T,U>::Type,N>
689 template <
typename T,
typename U,
int N>
690 Vector<typename Promote<T,U>::Type,N>
696 template <
typename T,
typename U,
int N>
697 Vector<typename Promote<T,U>::Type,N>
703 template <
typename T,
typename U,
int N>
704 Vector<typename Promote<T,U>::Type,N>
711 template <
typename T,
typename U,
int N>
712 Vector<typename Promote<T,U>::Type,N>
718 template <
typename T,
typename U,
int N>
719 Vector<typename Promote<T,U>::Type,N>
725 template <
typename T,
typename U,
int N>
726 Vector<typename Promote<T,U>::Type,N>
733 template <
typename T,
typename U,
int N>
734 Vector<typename Promote<T,U>::Type,N>
740 template <
typename T,
typename U,
int N>
741 Vector<typename Promote<T,U>::Type,N>
747 template <
typename T,
typename U,
int N>
748 Vector<typename Promote<T,U>::Type,N>
755 template <
typename T,
typename U,
int N>
756 Vector<typename Promote<T,U>::Type,N>
762 template <
typename T,
typename U,
int N>
763 Vector<typename Promote<T,U>::Type,N>
764 operator <<(Vector<T,N>
const & a, U
b) {
769 template <
typename T,
typename U,
int N>
770 Vector<typename Promote<T,U>::Type,N>
771 operator <<(U a, Vector<T,N>
const &
b) {
777 template <
typename T,
typename U,
int N>
778 Vector<typename Promote<T,U>::Type,N>
784 template <
typename T,
typename U,
int N>
785 Vector<typename Promote<T,U>::Type,N>
791 template <
typename T,
typename U,
int N>
792 Vector<typename Promote<T,U>::Type,N>
802 #endif // !NDARRAY_Vector_h_INCLUDED
Vector()
Default constructor.
< unspecified-expression-type > operator-(ExpressionBase< Operand > const &operand, Scalar const &scalar)
ConstReference const_reference
iterator end()
Return an iterator to the end of the Vector.
size_type size() const
Return the size of the Vector.
Vector< T, M > first() const
Create a new Vector from the first M elements of this.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator|=(Vector< U, N > const &other)
Augmented |= assignment from another vector.
Vector< T, M > last() const
Create a new Vector from the last M elements of this.
bool operator==(Vector const &other) const
Return true if elements of other are equal to the elements of this.
ConstIterator const_iterator
size_type max_size() const
Return the size of the Vector.
const_reference operator[](int i) const
Return a const_reference to the element with the given index.
reference operator[](int i)
Return a reference to the element with the given index.
bool operator!=(Vector const &other) const
Return false if any elements of other are not equal to the elements of this.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator=(Vector< U, N > const &other)
Augmented = assignment from another vector.
bool operator==(Vector const &other) const
Return true if elements of other are equal to the elements of this.
< unspecified-expression-type > operator~(ExpressionBase< Operand > const &operand)
< unspecified-expression-type > operator/(ExpressionBase< Operand > const &operand, Scalar const &scalar)
T product() const
Return the product of all elements.
reference front()
Return a reference to the first element.
Vector(U scalar)
Construct with copies of a scalar.
const_iterator begin() const
Return a const_iterator to the beginning of the Vector.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator*=(Vector< U, N > const &other)
Augmented *= assignment from another vector.
reverse_iterator rend()
Return a reverse_iterator to the end of the reversed Vector.
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
boost::reverse_iterator< T * > reverse_iterator
reference back()
Return a reference to the last element.
const_reference operator[](int i) const
Return a const_reference to the element with the given index.
const_reverse_iterator rend() const
Return a const_reverse_iterator to the end of the reversed Vector.
T sum() const
Return the sum of all elements.
reverse_iterator rend()
Return a reverse_iterator to the end of the reversed Vector.
Vector()
Default constructor.
< unspecified-expression-type > operator+(ExpressionBase< Operand > const &operand, Scalar const &scalar)
Vector reverse() const
Return a Vector with the elements reversed.
reference back()
Return a reference to the last element.
Forward declarations and default template parameters for ndarray.
bool empty() const
Return true if size() == 0.
T product() const
Return the product of all elements.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator&=(Vector< U, N > const &other)
Augmented &= assignment from another vector.
#define NDARRAY_ASSERT(ARG)
Vector< T, Stop-Start > getRange() const
Create a new Vector that is a subset of this.
ConstIterator const_iterator
ConstReference const_reference
A fixed-size 1D array class.
bool empty() const
Return true if size() == 0.
reference operator[](int i)
Return a reference to the element with the given index.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator-=(Vector< U, N > const &other)
Augmented -= assignment from another vector.
bool operator!=(Vector const &other) const
Return false if any elements of other are not equal to the elements of this.
Vector< T, M > last() const
Create a new Vector from the last M elements of this.
boost::reverse_iterator< const T * > const_reverse_iterator
iterator begin()
Return an iterator to the beginning of the Vector.
const_reference front() const
Return a const_reference to the first element.
Vector< T, N > operator!(Vector< T, N > const &vector)
Unary negation for Vector.
const_reverse_iterator rbegin() const
Return a const_reverse_iterator to the beginning of the reversed Vector.
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
const_reverse_iterator rbegin() const
Return a const_reverse_iterator to the beginning of the reversed Vector.
< unspecified-expression-type > operator*(ExpressionBase< Operand > const &operand, Scalar const &scalar)
const_reverse_iterator rend() const
Return a const_reverse_iterator to the end of the reversed Vector.
Vector< T, M > first() const
Create a new Vector from the first M elements of this.
< unspecified-expression-type > operator^(ExpressionBase< Operand > const &operand, Scalar const &scalar)
< unspecified-expression-type > operator%(ExpressionBase< Operand > const &operand, Scalar const &scalar)
const_reference back() const
Return a const_reference to the last element.
iterator end()
Return an iterator to the end of the Vector.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator/=(Vector< U, N > const &other)
Augmented /= assignment from another vector.
boost::reverse_iterator< const T * > const_reverse_iterator
Vector(Vector< U, 0 > const &other)
Converting copy constructor.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator>>=(Vector< U, N > const &other)
Augmented >>= assignment from another vector.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator^=(Vector< U, N > const &other)
Augmented ^= assignment from another vector.
< unspecified-expression-type > equal(ExpressionBase< Operand > const &operand, Scalar const &scalar)
reverse_iterator rbegin()
Return a reverse_iterator to the beginning of the reversed Vector.
const_reference front() const
Return a const_reference to the first element.
< unspecified-expression-type > operator&(ExpressionBase< Operand > const &operand, Scalar const &scalar)
afw::table::Key< double > b
size_type size() const
Return the size of the Vector.
const_iterator end() const
Return a const_iterator to the end of the Vector.
Vector< T, Stop-Start > getRange() const
Create a new Vector that is a subset of this.
Vector(Vector< U, N > const &other)
Converting copy constructor.
const_iterator begin() const
Return a const_iterator to the beginning of the Vector.
const_iterator end() const
Return a const_iterator to the end of the Vector.
const_reference back() const
Return a const_reference to the last element.
boost::reverse_iterator< T * > reverse_iterator
reference front()
Return a reference to the first element.
Vector< T, N+M > concatenate(Vector< T, N > const &a, Vector< T, M > const &b)
Concatenate two Vectors into a single long Vector.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator%=(Vector< U, N > const &other)
Augmented %= assignment from another vector.
Vector(U scalar)
Construct with copies of a scalar.
< unspecified-expression-type > operator|(ExpressionBase< Operand > const &operand, Scalar const &scalar)
T sum() const
Return the sum of all elements.
size_type max_size() const
Return the size of the Vector.
reverse_iterator rbegin()
Return a reverse_iterator to the beginning of the reversed Vector.
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator<<=(Vector< U, N > const &other)
Augmented <<= assignment from another vector.
Vector reverse() const
Return a Vector with the elements reversed.
< unspecified-expression-type > operator>>(ExpressionBase< Operand > const &operand, Scalar const &scalar)
boost::enable_if< boost::is_convertible< U, T >, Vector & >::type operator+=(Vector< U, N > const &other)
Augmented += assignment from another vector.