QVM: Quaternions, Vectors, Matrices

boost/qvm/vec.hpp

This header defines the struct vec template, which acts as a generic vector type.

Synopsis:

#include <boost/qvm/vec.hpp>

namespace boost
{
    namespace qvm
    {
        template <class T,int Dim>
        struct vec
        {
            T a[Dim];
        
            template <class R>
            operator R() const
            {
                R r;
                assign(r,*this);
                return r;
            }
        };
        
        template <class Vector>
        struct vec_traits;
        
        template <class T,int Dim>
        struct vec_traits< vec<T,Dim> >
        {
            typedef T scalar_type;
            static int const dim=Dim;
        
            template <int I> static scalar_type read_element( vec<T,Dim> const & x ) { return x.a[I]; }
            template <int I> static scalar_type & write_element( vec<T,Dim> & x ) { return x.a[I]; }
        
            static scalar_type read_element_idx( int i, vec<T,Dim> const & x ) { return x.a[i]; }
            static scalar_type & write_element_idx( int i, vec<T,Dim> & x ) { return x.a[i]; }
        };
    }
}

See also: vec