Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

QVM: Quaternions, Vectors, Matrices

Accessing Vector Elements

#include <boost/qvm/vec_access.hpp>

namespace boost
{
    namespace qvm
    {
        //Only enabled if:
        //  is_vec<V>::value
        
        template <int I,class V> -unspecified-return-type- A( V & v );
        template <class V> -unspecified-return-type- A0( V & v );
        template <class V> -unspecified-return-type- A1( V & v );
        ...
        template <class V> -unspecified-return-type- A9( V & v );
        
        template <class V> -unspecified-return-type- X( V & v );
        template <class V> -unspecified-return-type- Y( V & v );
        template <class V> -unspecified-return-type- Z( V & v );
        template <class V> -unspecified-return-type- W( V & v );
    }
}

An expression of the form of A<I>(v) can be used to access the I-th element a vector object v. For example, the expression:

A<1>(v) *= 42;

can be used to multiply the element at index 1 (indexing in Boost QVM is always zero-based) of a vector v by 42.

For convenience, there are also non-template overloads for I from 0 to 9; an alternative way to write the above expression is:

A1(v) *= 42;

X, Y, Z and W act the same as A0/A1/A2/A3; yet another alternative way to write the above expression is:

Y(v) *= 42;