| 1 | // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. |
| 2 | |
| 3 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 4 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 5 | |
| 6 | #ifndef BOOST_QVM_VEC_TRAITS_HPP_INCLUDED |
| 7 | #define BOOST_QVM_VEC_TRAITS_HPP_INCLUDED |
| 8 | |
| 9 | #include <boost/qvm/is_scalar.hpp> |
| 10 | #include <boost/qvm/enable_if.hpp> |
| 11 | #include <boost/qvm/config.hpp> |
| 12 | |
| 13 | namespace boost { namespace qvm { |
| 14 | |
| 15 | template <class V> |
| 16 | struct |
| 17 | vec_traits |
| 18 | { |
| 19 | static int const dim=0; |
| 20 | typedef void scalar_type; |
| 21 | }; |
| 22 | |
| 23 | template <class T> |
| 24 | struct |
| 25 | is_vec |
| 26 | { |
| 27 | static bool const value = is_scalar<typename vec_traits<T>::scalar_type>::value && vec_traits<T>::dim>0; |
| 28 | }; |
| 29 | |
| 30 | namespace |
| 31 | qvm_detail |
| 32 | { |
| 33 | template <class T, T> |
| 34 | struct |
| 35 | vtr_dispatch_yes |
| 36 | { |
| 37 | char x, y; |
| 38 | }; |
| 39 | } |
| 40 | |
| 41 | template <class T> |
| 42 | class |
| 43 | vec_write_element_ref |
| 44 | { |
| 45 | template <class U> |
| 46 | static qvm_detail::vtr_dispatch_yes<typename vec_traits<U>::scalar_type & (*)( U & ), &vec_traits<U>::template write_element<0> > check(int); |
| 47 | |
| 48 | template <class> |
| 49 | static char check(long); |
| 50 | |
| 51 | public: |
| 52 | |
| 53 | static bool const value = sizeof(check<T>(0)) > 1; |
| 54 | }; |
| 55 | |
| 56 | template <int I, class V> |
| 57 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 58 | typename enable_if_c< |
| 59 | vec_write_element_ref<V>::value, |
| 60 | void>::type |
| 61 | write_vec_element( V & v, typename vec_traits<V>::scalar_type s ) |
| 62 | { |
| 63 | vec_traits<V>::template write_element<I>(v) = s; |
| 64 | } |
| 65 | |
| 66 | template <int I, class V> |
| 67 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 68 | typename enable_if_c< |
| 69 | !vec_write_element_ref<V>::value, |
| 70 | void>::type |
| 71 | write_vec_element( V & v, typename vec_traits<V>::scalar_type s ) |
| 72 | { |
| 73 | vec_traits<V>::template write_element<I>(v, s); |
| 74 | } |
| 75 | |
| 76 | template <class V> |
| 77 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 78 | typename enable_if_c< |
| 79 | vec_write_element_ref<V>::value, |
| 80 | void>::type |
| 81 | write_vec_element_idx( int i, V & v, typename vec_traits<V>::scalar_type s ) |
| 82 | { |
| 83 | vec_traits<V>::write_element_idx(i, v) = s; |
| 84 | } |
| 85 | |
| 86 | template <class V> |
| 87 | BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL |
| 88 | typename enable_if_c< |
| 89 | !vec_write_element_ref<V>::value, |
| 90 | void>::type |
| 91 | write_vec_element_idx( int i, V & v, typename vec_traits<V>::scalar_type s ) |
| 92 | { |
| 93 | vec_traits<V>::write_element_idx(i, v, s); |
| 94 | } |
| 95 | |
| 96 | } } |
| 97 | |
| 98 | #endif |
| 99 | |