1#ifndef BOOST_QVM_VEC_HPP_INCLUDED
2#define BOOST_QVM_VEC_HPP_INCLUDED
3
4// Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc.
5
6// Distributed under the Boost Software License, Version 1.0. (See accompanying
7// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8
9#include <boost/qvm/detail/vec_assign.hpp>
10#include <boost/qvm/assert.hpp>
11#include <boost/qvm/static_assert.hpp>
12
13namespace boost { namespace qvm {
14
15template <class T,int D>
16struct
17vec
18 {
19 T a[D];
20 template <class R
21#if __cplusplus >= 201103L
22 , class = typename enable_if<is_vec<R> >::type
23#endif
24 >
25 operator R() const
26 {
27 R r;
28 assign(r,*this);
29 return r;
30 }
31 };
32
33template <class V>
34struct vec_traits;
35
36template <class T,int Dim>
37struct
38vec_traits< vec<T,Dim> >
39 {
40 typedef vec<T,Dim> this_vector;
41 typedef T scalar_type;
42 static int const dim=Dim;
43
44 template <int I>
45 static
46 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
47 scalar_type
48 read_element( this_vector const & x )
49 {
50 BOOST_QVM_STATIC_ASSERT(I>=0);
51 BOOST_QVM_STATIC_ASSERT(I<dim);
52 return x.a[I];
53 }
54
55 template <int I>
56 static
57 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
58 scalar_type &
59 write_element( this_vector & x )
60 {
61 BOOST_QVM_STATIC_ASSERT(I>=0);
62 BOOST_QVM_STATIC_ASSERT(I<dim);
63 return x.a[I];
64 }
65
66 static
67 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
68 scalar_type
69 read_element_idx( int i, this_vector const & x )
70 {
71 BOOST_QVM_ASSERT(i>=0);
72 BOOST_QVM_ASSERT(i<dim);
73 return x.a[i];
74 }
75
76 static
77 BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL
78 scalar_type &
79 write_element_idx( int i, this_vector & x )
80 {
81 BOOST_QVM_ASSERT(i>=0);
82 BOOST_QVM_ASSERT(i<dim);
83 return x.a[i];
84 }
85 };
86
87} }
88
89#endif
90

source code of boost/libs/qvm/include/boost/qvm/vec.hpp