#include <vector.h>
Public Types | |
| typedef t_Type | value_type |
Public Member Functions | |
| t_Type & | operator[] (size_t const index) |
| t_Type const & | operator[] (size_t const index) const |
| Vector const & | operator= (Vector const &other) |
| t_Type | Sum () const |
| Returns the sum of all elements. | |
| t_Type | Product () const |
| Returns the product of all elements. | |
| t_Type | Maximum () const |
| Returns the maximum element. | |
| t_Type | Minimum () const |
| Returns the minimum element. | |
| t_Type | NormSquared () const |
| Returns the sum of the squares of the elements. | |
| RESULT_TYPE (std::sqrt(*static_cast< t_Type const * >(NULL))) Norm() const | |
| Returns the 2-norm of the vector (the square root of the sum of the squares of the elements). | |
Public Attributes | |
| t_Type | data [t_Size] |
Vector class.
| t_Type | Type of elements. |
| t_Size | Number of elements. |
This class is an awful lot like std::array, with the main difference being that, for Vectors, a large number of operators and functions are also defined. Like std::array, it supports aggregate initialization, meaning that you can initialize a Vector as:
Vector< float, 3 > vector = { { 1, 0, -1 } };
Every C++ operator is overloaded, including the bitwise operators, except for the pre/post increment/decrement operators ++ and --. Comparisons are lexicographic, like std::array, which enables instances of this class to be used in standard containers (although one could make a case for vector comparisons returning vector results, with the comparison being performed element-by-element). Also, many standard math functions have Vector overloads, including everything relevant in the cmath header, std::min and std::max, and the Square and Cube functions found in helpers.h. Adding new function overloads is pretty simple: see VECTOR_FUNCTION() and the related macros.
The operators and functions which work on this class try to follow the same automatic casting rules as the underlying operations. For example, if you add a Vector< float, 3 > to a Vector< int, 3 >, the result will be a Vector< float, 3 >, with the result type being determined from that of scalar addition of a float and an int (using decltype).
1.8.1.2