#include <boost/la/vector_traits.hpp>
namespace
boost
{
namespace
la
{
template <class V>
struct
vector_traits
{
/*main template members unspecified*/
};
/*
User-defined (partial) specializations:
template <>
struct
vector_traits< Vector >
{
static int const dim = /*user-defined*/;
typedef /*user-defined*/ scalar_type;
template <int I> static inline scalar_type r( Vector const & v );
template <int I> static inline scalar_type & w( Vector & v );
static inline scalar_type ir( int i, Vector const & v );
static inline scalar_type & iw( int i, Vector & v );
};
*/
}
}
The vector_traits template must be specialized for (user-defined) vector types in order to enable vector and matrix operations defined in Boost LA headers for objects of those types.
Note: vector types are not required to be copyable.
The main vector_traits template members are not specified. Valid specializations are required to define the following members:
In addition, valid specializations of the vector_traits template must define the following access functions as static members, where v is an object of type Vector, I is a compile-time integer constant, and i is a variable of type int:
It is illegal to call any of the above functions unless is_vector<Vector>::value is true. Even then, vector types are allowed to define only a subset of the access functions. The general requirements are:
In addition, every Boost LA function that takes vector type parameter(s) specifies whether it requires read-only, write-only or read-and-write access.
Below is an example of a user-defined 3D vector type, and its corresponding specialization of the vector_traits template:
#include <boost/la/vector_traits.hpp> struct float3 { float a[3]; }; namespace boost { namespace la { template <> struct vector_traits<float3> { static int const dim=3; typedef float scalar_type; template <int I> static inline scalar_type & w( float3 & v ) { return v.a[I]; } template <int I> static inline scalar_type r( float3 const & v ) { return v.a[I]; } static inline scalar_type & iw( int i, float3 & v ) { return v.a[i]; } static inline scalar_type ir( int i, float3 const & v ) { return v.a[i]; } }; } }