Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:49:53

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