Voxel
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Macros Pages
Public Types | Public Member Functions | Public Attributes | List of all members
Vector< t_Type, t_Size > Struct Template Reference

Vector class. More...

#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]

Detailed Description

template<typename t_Type, size_t t_Size>
struct Vector< t_Type, t_Size >

Vector class.

Parameters
t_TypeType of elements.
t_SizeNumber 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).

Definition at line 96 of file vector.h.


The documentation for this struct was generated from the following file: