File indexing completed on 2025-01-18 09:51:08
0001 #ifndef BOOST_QVM_VEC_HPP_INCLUDED
0002 #define BOOST_QVM_VEC_HPP_INCLUDED
0003
0004
0005
0006
0007
0008
0009 #include <boost/qvm/detail/vec_assign.hpp>
0010 #include <boost/qvm/assert.hpp>
0011 #include <boost/qvm/static_assert.hpp>
0012
0013 namespace boost { namespace qvm {
0014
0015 template <class T,int D>
0016 struct
0017 vec
0018 {
0019 T a[D];
0020 template <class R
0021 #if __cplusplus >= 201103L
0022 , class = typename enable_if<is_vec<R> >::type
0023 #endif
0024 >
0025 operator R() const
0026 {
0027 R r;
0028 assign(r,*this);
0029 return r;
0030 }
0031 };
0032
0033 template <class V>
0034 struct vec_traits;
0035
0036 template <class T,int Dim>
0037 struct
0038 vec_traits< vec<T,Dim> >
0039 {
0040 typedef vec<T,Dim> this_vector;
0041 typedef T scalar_type;
0042 static int const dim=Dim;
0043
0044 template <int I>
0045 static
0046 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0047 scalar_type
0048 read_element( this_vector const & x )
0049 {
0050 BOOST_QVM_STATIC_ASSERT(I>=0);
0051 BOOST_QVM_STATIC_ASSERT(I<dim);
0052 return x.a[I];
0053 }
0054
0055 template <int I>
0056 static
0057 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0058 scalar_type &
0059 write_element( this_vector & x )
0060 {
0061 BOOST_QVM_STATIC_ASSERT(I>=0);
0062 BOOST_QVM_STATIC_ASSERT(I<dim);
0063 return x.a[I];
0064 }
0065
0066 static
0067 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0068 scalar_type
0069 read_element_idx( int i, this_vector const & x )
0070 {
0071 BOOST_QVM_ASSERT(i>=0);
0072 BOOST_QVM_ASSERT(i<dim);
0073 return x.a[i];
0074 }
0075
0076 static
0077 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0078 scalar_type &
0079 write_element_idx( int i, this_vector & x )
0080 {
0081 BOOST_QVM_ASSERT(i>=0);
0082 BOOST_QVM_ASSERT(i<dim);
0083 return x.a[i];
0084 }
0085 };
0086
0087 } }
0088
0089 #endif