#ifndef BOOST_QVM_TRAITS_HPP_INCLUDED #define BOOST_QVM_TRAITS_HPP_INCLUDED // Copyright 2008-2022 Emil Dotchevski and Reverge Studios, Inc. // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include #include #include namespace boost { namespace qvm { template struct mat_traits { static int const rows=0; static int const cols=0; typedef void scalar_type; }; template struct is_mat { static bool const value = is_scalar::scalar_type>::value && mat_traits::rows>0 && mat_traits::cols>0; }; namespace qvm_detail { template struct mtr_dispatch_yes { char x, y; }; } template class mat_write_element_ref { template static qvm_detail::mtr_dispatch_yes::scalar_type & (*)( U & ), &mat_traits::template write_element<0,0> > check(int); template static char check(long); public: static bool const value = sizeof(check(0)) > 1; }; template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL typename enable_if_c< mat_write_element_ref::value, void>::type write_mat_element( M & m, typename mat_traits::scalar_type s ) { mat_traits::template write_element(m) = s; } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL typename enable_if_c< !mat_write_element_ref::value, void>::type write_mat_element( M & m, typename mat_traits::scalar_type s ) { mat_traits::template write_element(m, s); } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL typename enable_if_c< mat_write_element_ref::value, void>::type write_mat_element_idx( int r, int c, M & m, typename mat_traits::scalar_type s ) { mat_traits::write_element_idx(r, c, m) = s; } template BOOST_QVM_CONSTEXPR BOOST_QVM_INLINE_CRITICAL typename enable_if_c< !mat_write_element_ref::value, void>::type write_mat_element_idx( int r, int c, M & m, typename mat_traits::scalar_type s ) { mat_traits::write_element_idx(r, c, m, s); } } } #endif