Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:59:09

0001 #ifndef BOOST_QVM_VEC_TRAITS_DEFAULTS_HPP_INCLUDED
0002 #define BOOST_QVM_VEC_TRAITS_DEFAULTS_HPP_INCLUDED
0003 
0004 // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
0005 
0006 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0007 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #include <boost/qvm/config.hpp>
0010 #include <boost/qvm/assert.hpp>
0011 
0012 namespace boost { namespace qvm {
0013 
0014 template <class>
0015 struct vec_traits;
0016 
0017 namespace
0018 qvm_detail
0019     {
0020     template <int I,int N>
0021     struct
0022     vector_w
0023         {
0024         template <class A>
0025         static
0026         BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0027         typename vec_traits<A>::scalar_type &
0028         write_element_idx( int i, A & a )
0029             {
0030             return I==i?
0031                 vec_traits<A>::template write_element<I>(a) :
0032                 vector_w<I+1,N>::write_element_idx(i,a);
0033             }
0034         };
0035 
0036     template <int N>
0037     struct
0038     vector_w<N,N>
0039         {
0040         template <class A>
0041         static
0042         BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0043         typename vec_traits<A>::scalar_type &
0044         write_element_idx( int, A & a )
0045             {
0046             BOOST_QVM_ASSERT(0);
0047             return vec_traits<A>::template write_element<0>(a);
0048             }
0049         };
0050     }
0051 
0052 template <class VecType,class ScalarType,int Dim>
0053 struct
0054 vec_traits_defaults
0055     {
0056     typedef VecType vec_type;
0057     typedef ScalarType scalar_type;
0058     static int const dim=Dim;
0059 
0060     template <int I>
0061     static
0062     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0063     scalar_type
0064     read_element( vec_type const & x )
0065         {
0066         return vec_traits<vec_type>::template write_element<I>(const_cast<vec_type &>(x));
0067         }
0068 
0069     static
0070     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0071     scalar_type
0072     read_element_idx( int i, vec_type const & x )
0073         {
0074         return vec_traits<vec_type>::write_element_idx(i,const_cast<vec_type &>(x));
0075         }
0076 
0077     protected:
0078 
0079     static
0080     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_TRIVIAL
0081     scalar_type &
0082     write_element_idx( int i, vec_type & m )
0083         {
0084         return qvm_detail::vector_w<0,vec_traits<vec_type>::dim>::write_element_idx(i,m);
0085         }
0086     };
0087 
0088 } }
0089 
0090 #endif