Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 08:51:38

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