Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:04:07

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