1 #ifndef TIL_NUMERIC_ARRAY_H 2 #define TIL_NUMERIC_ARRAY_H 5 #include "boost/array.hpp" 6 #include "boost/call_traits.hpp" 56 template <
typename T, std::
size_t D >
59 ,
public numeric_container_label
105 std::size_t
size()
const {
return D; }
109 iterator
begin() {
return iterator(this->Base::begin()); }
110 iterator
end() {
return iterator(this->Base::end()); }
111 const_iterator
begin()
const {
return const_iterator(this->Base::begin()); }
112 const_iterator
end()
const {
return const_iterator(this->Base::end()); }
114 reverse_iterator
rbegin() {
return this->Base::rbegin(); }
115 reverse_iterator
rend() {
return this->Base::rend(); }
116 const_reverse_iterator
rbegin()
const {
return this->Base::rbegin(); }
117 const_reverse_iterator
rend()
const {
return this->Base::rend(); }
130 return this->elems[n];
136 return this->elems[n];
142 #define TIL_DEFINE(op) \ 143 template < typename T2 > \ 144 void operator op (const numeric_array_impl<T2,D> & v) \ 145 { for (std::size_t i = 0; i < D; ++i) (*this)[i] op v[i]; } \ 157 {
for (std::size_t i = 0; i < D; ++i) (*
this)[i] += x; }
159 {
for (std::size_t i = 0; i < D; ++i) (*
this)[i] -= x; }
161 {
for (std::size_t i = 0; i < D; ++i) (*
this)[i] *= x; }
164 { this->divide(x, cat2type<is_floating_point, T>()); }
170 template <
typename X >
175 template <
typename X >
177 {
for (std::size_t i = 0; i < D; ++i) (*
this)[i] /= x; }
214 template <
typename T, std::
size_t D >
227 template <
typename T, std::
size_t D >
241 template <
typename T, std::
size_t D >
243 :
public basic_range<typename numeric_array_impl<T,D>::iterator>
252 template <
typename T, std::
size_t D >
268 template <
typename T, std::
size_t D >
290 template <
typename T >
310 void init(T x, T y, T z) { (*this)[0] = x; (*this)[1] = y; (*this)[2] = z; }
An implementation of a numeric array.
numeric_array_impl< T, D >::iterator iterator
Base::const_reverse_iterator const_reverse_iterator
numeric_array(T x, T y, T z)
const_iterator(const T *p)
void operator+=(const T &x)
const_iterator begin() const
detail::numeric_array_impl< T, 3 > Base
Belongs to package Box Do not include directly, include til/Box.h instead.
const_reverse_iterator rbegin() const
numeric_array(const numeric_array< T, 3 > &x)
const T & operator[](std::size_t n) const
Read access to n-th value.
Defines empty classes that serves as labels.
const_range whole_range() const
A simple wrapper around T*.
boost::array< T, D > Base
range(iterator begin, iterator end)
const_reverse_iterator rend() const
basic_range< const_iterator > Base
numeric_array_impl()
Default constructor.
void operator-=(const T &x)
void operator/=(const T &x)
numeric_array_impl< T, D > Self
basic_iterator< const T > Base
const_iterator(iterator i)
T & operator[](std::size_t n)
Read-write access to n-th value.
void operator*=(const T &x)
A label corresponding to a positive answer of a specific is_a test.
const_range(const_iterator begin, const_iterator end)
numeric_array(const numeric_array< T, D > &x)
const_iterator end() const
A simple range made out of a couple of iterators.
Base::reverse_iterator reverse_iterator
std::size_t size() const
Standard constructors.
basic_range< iterator > Base
reverse_iterator rbegin()
detail::numeric_array_impl< T, D > Base
A label corresponding to a negative answer of a specific is_a test.