Meta
Meta-Programming tools.
Interface
ValueType
The class ValueType offers a typedef value_type which is either the type
of the template parameter itself (for basic types) of the type of the elements
containted within the type of the template parameter (for containers).
The full definition is:
template <typename T>
struct ValueType;
Intended to facilitate the integration of arithmic types and containers
of arithmic types such as Vectors. The
ValueType defines a value_type. For arithmic types, this is the
type itself; for other types, such as containers, this is the type of elements
in the container. The latter is implemented as an alias for
T::value_type, which must be defined in the implementation of
container-type T.
value_type |
A type definition. |
Consider the following example:
template <typename T>
typename ValueType<T>::value_type modulus(const T &arraymp;x);
The definition specifies that if T is an arithmetic type, the return type
is also T. If T is not an arithmetic type, such as a
Vector, the return type is T::value_type, the
type of the elements of T. Thus, if T is an int, then
ValueType<T>::value_type is an int. If T is a
StaticVector<float, 3u>, then
ValueType<T>::value_type is a float.
promote_trait1, promote_trait2, promote_trait3
Promote types to floating-point representations, if possible with a sufficiently
long mantissa to accurately represent the original type.
static_max
A max() function that can be used in template expressions.
template <int lhs, int rhs>
struct static_max;
The struct static_max defines an int max.
static_log2
A function that uses template techniques to calculate the log2 of a value during
compilation.
template <std::size_t N>
std::size_t static_log2();
Contrary to dynamically executed log2 functions, the value can then be used
during compilation, such as for template parameters.
array_traits
The class array_traits offers a uniform interface to the many
multi-dimensional array implementations available in C++, such as CVMLCPP' own
Matrix, boosts'
multi_array, and
blitz++'s
Arrays through the
BlitzArray class.
The purpose is to allow programmers the use this uniform interface in stead of
the interfaces offered by the individual implementations. This makes it
possible to switch from one implementation to another with significantly less
effort.
The full definition is:
template <template <typename Tm, std::size_t D, typename Aux>
class Array_t, typename T, std::size_t N, typename A>
struct array_traits;
array_traits contains both typedefs and member functions.
Using array_traits, specialisations for std::swap() are offered,
so that it always uses the most efficient swap implementation for given matrix
arguments. The use of any form of swap() on matrices of different types
is strongly discouraged as it requires copying all data.
array_type |
The full type of the array, i.e. Array_t<T, N, A>. |
value_type |
The type of the elements in the array, i.e. an alias for
template parameter T. |
iterator |
The iterator type over the contents of the array. |
const_iterator |
A const_iterator type (read-only) over the contents of the
array. |
reference |
The type of a reference to the elements of the array. |
const_reference |
The type of a read-only reference to the elements of the array. |
slice_type |
The type of a slice of the array. Slices have reference
semantics, and cannot be resized. |
slice_traits |
The array_traits type for slices of the array. |
template <typename InputIterator>
array_type create(InputIterator input) |
Returns a newly created array with dimensions as specified in
the range indicated by input. |
template <typename InputIterator>
array_type create(InputIterator input, const T &value) |
Returns a newly created array with dimensions as specified in
the range indicated by input, filled with value. |
std::size_t size(const array_type &array) |
The number of elements in the array. |
template <typename InputIterator>
bool resize(Array_t<T, N, Aux> &array, InputIterator input,
bool preserve = false) |
Resize the array to the dimensions specified in
the range indicated by input, trying to preserve the
contents only if preserve is true. |
integer_type_const_iterator
shape(const Array_t<T, N, Aux> &array |
Returns an iterator to the beginning of a range indicating the
shape / dimensions / extents of the array. The exact type
of integer_type_const_iterator depends on the
implementation. |
array_type ©_of(const array_type &array) |
Returns a new array that is a copy of the given array. |
iterator begin(array_type &array) |
Returns an iterator pointing to the first element in
array. |
const_iterator begin(const array_type &array) |
Returns a const_iterator pointing to the first element in
array. |
iterator end(array_type &array) |
Returns an iterator pointing to the end of array. |
const_iterator end(const array_type &array) |
Returns an const_iterator pointing to the end of array. |
void swap(array_type &lhs, array_type &rhs) |
Equivalent of std::swap(), chooses optimal
implementation. |
Array Functions
There is a special function, copy(), that copies arrays of
potentially different types and sizes. If the destination is in any
dimension smaller than the source, the remaining elements will not
be copied. If the destination is greater than the source in any
dimension, the destination remaining data are by default set to zero.
This behavior can be controlled by the pad_zero parameter.
The template parameter N refers to the number of dimensions of the arrays
to be copied.
template < ... >
void copy(const ArrayIn <Tin, N, AuxLhs> & input,
ArrayOut<Tout, N, AuxRhs> &output, const bool pad_zero = true);
The function clear() resizes the any array to zero in any dimension, effectively
clearing it of any data.
template < ... >
void clear(Array<T, N, A> &m);
|