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_ARRAY_HPP_INCLUDED
0002 #define BOOST_QVM_VEC_TRAITS_ARRAY_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/deduce_vec.hpp>
0011 #include <boost/qvm/assert.hpp>
0012 
0013 #if __cplusplus > 199711L
0014 
0015 #include <array>
0016 
0017 namespace boost { namespace qvm {
0018 
0019 template <class T,std::size_t M,std::size_t N>
0020 struct
0021 vec_traits<std::array<std::array<T,M>,N> >
0022     {
0023     static int const dim=0;
0024     typedef void scalar_type;
0025     };
0026 
0027 template <class T,std::size_t Dim>
0028 struct
0029 vec_traits<std::array<T, Dim> >
0030     {
0031     typedef std::array<T, Dim> this_vector;
0032     typedef T scalar_type;
0033     static int const dim=int(Dim);
0034 
0035     template <int I>
0036     static
0037     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0038     scalar_type
0039     read_element( this_vector const & x )
0040         {
0041         BOOST_QVM_STATIC_ASSERT(I>=0);
0042         BOOST_QVM_STATIC_ASSERT(I<int(Dim));
0043         return x[I];
0044         }
0045 
0046     template <int I>
0047     static
0048     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0049     scalar_type &
0050     write_element( this_vector & x )
0051         {
0052         BOOST_QVM_STATIC_ASSERT(I>=0);
0053         BOOST_QVM_STATIC_ASSERT(I<int(Dim));
0054         return x[I];
0055         }
0056 
0057     static
0058     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0059     scalar_type
0060     read_element_idx( int i, this_vector const & x )
0061         {
0062         BOOST_QVM_ASSERT(i>=0);
0063         BOOST_QVM_ASSERT(i<int(Dim));
0064         return x[i];
0065         }
0066 
0067     static
0068     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0069     scalar_type &
0070     write_element_idx( int i, this_vector & x )
0071         {
0072         BOOST_QVM_ASSERT(i>=0);
0073         BOOST_QVM_ASSERT(i<int(Dim));
0074         return x[i];
0075         }
0076     };
0077 
0078 template <class T,std::size_t Dim>
0079 struct
0080 vec_traits<std::array<T, Dim> const>
0081     {
0082     typedef std::array<T, Dim> const this_vector;
0083     typedef T scalar_type;
0084     static int const dim=int(Dim);
0085 
0086     template <int I>
0087     static
0088     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0089     scalar_type
0090     read_element( this_vector & x )
0091         {
0092         BOOST_QVM_STATIC_ASSERT(I>=0);
0093         BOOST_QVM_STATIC_ASSERT(I<int(Dim));
0094         return x[I];
0095         }
0096 
0097     static
0098     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0099     scalar_type
0100     read_element_idx( int i, this_vector & x )
0101         {
0102         BOOST_QVM_ASSERT(i>=0);
0103         BOOST_QVM_ASSERT(i<int(Dim));
0104         return x[i];
0105         }
0106     };
0107 
0108 template <class T,std::size_t Dim,int D>
0109 struct
0110 deduce_vec<std::array<T,Dim>,D>
0111     {
0112     typedef vec<T,D> type;
0113     };
0114 
0115 template <class T,std::size_t Dim,int D>
0116 struct
0117 deduce_vec<std::array<T,Dim> const,D>
0118     {
0119     typedef vec<T,D> type;
0120     };
0121 
0122 template <class T1,class T2,std::size_t Dim,int D>
0123 struct
0124 deduce_vec2<std::array<T1,Dim>,std::array<T2,Dim>,D>
0125     {
0126     typedef vec<typename deduce_scalar<T1,T2>::type,D> type;
0127     };
0128 
0129 template <class T1,class T2,std::size_t Dim,int D>
0130 struct
0131 deduce_vec2<std::array<T1,Dim> const,std::array<T2,Dim>,D>
0132     {
0133     typedef vec<typename deduce_scalar<T1,T2>::type,D> type;
0134     };
0135 
0136 template <class T1,class T2,std::size_t Dim,int D>
0137 struct
0138 deduce_vec2<std::array<T1,Dim>,std::array<T2,Dim> const,D>
0139     {
0140     typedef vec<typename deduce_scalar<T1,T2>::type,D> type;
0141     };
0142 
0143 template <class T1,class T2,std::size_t Dim,int D>
0144 struct
0145 deduce_vec2<std::array<T1,Dim> const,std::array<T2,Dim> const,D>
0146     {
0147     typedef vec<typename deduce_scalar<T1,T2>::type,D> type;
0148     };
0149 
0150 } }
0151 
0152 #endif
0153 
0154 namespace boost { namespace qvm {
0155 
0156 template <class T,int M,int N>
0157 struct
0158 vec_traits<T[M][N]>
0159     {
0160     static int const dim=0;
0161     typedef void scalar_type;
0162     };
0163 
0164 template <class T,int Dim>
0165 struct
0166 vec_traits<T[Dim]>
0167     {
0168     typedef T this_vector[Dim];
0169     typedef T scalar_type;
0170     static int const dim=Dim;
0171 
0172     template <int I>
0173     static
0174     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0175     scalar_type
0176     read_element( this_vector const & x )
0177         {
0178         BOOST_QVM_STATIC_ASSERT(I>=0);
0179         BOOST_QVM_STATIC_ASSERT(I<Dim);
0180         return x[I];
0181         }
0182 
0183     template <int I>
0184     static
0185     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0186     scalar_type &
0187     write_element( this_vector & x )
0188         {
0189         BOOST_QVM_STATIC_ASSERT(I>=0);
0190         BOOST_QVM_STATIC_ASSERT(I<Dim);
0191         return x[I];
0192         }
0193 
0194     static
0195     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0196     scalar_type
0197     read_element_idx( int i, this_vector const & x )
0198         {
0199         BOOST_QVM_ASSERT(i>=0);
0200         BOOST_QVM_ASSERT(i<Dim);
0201         return x[i];
0202         }
0203 
0204     static
0205     BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
0206     scalar_type &
0207     write_element_idx( int i, this_vector & x )
0208         {
0209         BOOST_QVM_ASSERT(i>=0);
0210         BOOST_QVM_ASSERT(i<Dim);
0211         return x[i];
0212         }
0213     };
0214 
0215 template <class T,int Dim,int D>
0216 struct
0217 deduce_vec<T[Dim],D>
0218     {
0219     typedef vec<T,D> type;
0220     };
0221 
0222 template <class T,int Dim,int D>
0223 struct
0224 deduce_vec<T const[Dim],D>
0225     {
0226     typedef vec<T,D> type;
0227     };
0228 
0229 template <class T1,class T2,int Dim,int D>
0230 struct
0231 deduce_vec2<T1[Dim],T2[Dim],D>
0232     {
0233     typedef vec<typename deduce_scalar<T1,T2>::type,D> type;
0234     };
0235 
0236 template <int Dim,class T>
0237 T (&ptr_vref( T * ptr ))[Dim]
0238     {
0239     return *reinterpret_cast<T (*)[Dim]>(ptr);
0240     }
0241 
0242 } }
0243 
0244 #endif