diff --git a/include/xtensor/core/xfunction.hpp b/include/xtensor/core/xfunction.hpp index 8f85892fb..200a35d47 100644 --- a/include/xtensor/core/xfunction.hpp +++ b/include/xtensor/core/xfunction.hpp @@ -355,24 +355,6 @@ namespace xt private: - template - layout_type layout_impl(std::index_sequence) const noexcept; - - template - const_reference access_impl(std::index_sequence, Args... args) const; - - template - const_reference unchecked_impl(std::index_sequence, Args... args) const; - - template - const_reference element_access_impl(std::index_sequence, It first, It last) const; - - template - const_reference data_element_impl(std::index_sequence, size_type i) const; - - template - auto load_simd_impl(std::index_sequence, size_type i) const; - template const_stepper build_stepper(Func&& f, std::index_sequence) const noexcept; @@ -437,9 +419,6 @@ namespace xt using data_type = std::tuple>()))...>; - template - reference deref_impl(std::index_sequence) const; - template difference_type tuple_max_diff(std::index_sequence, const data_type& lhs, const data_type& rhs) const; @@ -500,12 +479,6 @@ namespace xt private: - template - reference deref_impl(std::index_sequence) const; - - template - simd_return_type step_simd_impl(std::index_sequence); - const xfunction_type* p_f; std::tuple::const_stepper...> m_st; }; @@ -593,7 +566,13 @@ namespace xt template inline layout_type xfunction::layout() const noexcept { - return layout_impl(std::make_index_sequence()); + return std::apply( + [&](auto&... e) + { + return compute_layout(e.layout()...); + }, + m_e + ); } template @@ -628,7 +607,16 @@ namespace xt { // The static cast prevents the compiler from instantiating the template methods with signed integers, // leading to warning about signed/unsigned conversions in the deeper layers of the access methods - return access_impl(std::make_index_sequence(), static_cast(args)...); + + return std::apply( + [&](auto&... e) + { + XTENSOR_TRY(check_index(shape(), args...)); + XTENSOR_CHECK_DIMENSION(shape(), args...); + return m_f(e(args...)...); + }, + m_e + ); } /** @@ -643,7 +631,13 @@ namespace xt template inline auto xfunction::flat(size_type index) const -> const_reference { - return data_element_impl(std::make_index_sequence(), index); + return std::apply( + [&](auto&... e) + { + return m_f(e.data_element(index)...); + }, + m_e + ); } /** @@ -671,7 +665,13 @@ namespace xt { // The static cast prevents the compiler from instantiating the template methods with signed integers, // leading to warning about signed/unsigned conversions in the deeper layers of the access methods - return unchecked_impl(std::make_index_sequence(), static_cast(args)...); + return std::apply( + [&](const auto&... e) + { + return m_f(e.unchecked(static_cast(args)...)...); + }, + m_e + ); } /** @@ -685,7 +685,14 @@ namespace xt template inline auto xfunction::element(It first, It last) const -> const_reference { - return element_access_impl(std::make_index_sequence(), first, last); + return std::apply( + [&](auto&... e) + { + XTENSOR_TRY(check_element_index(shape(), first, last)); + return m_f(e.element(first, last)...); + }, + m_e + ); } //@} @@ -819,7 +826,13 @@ namespace xt template inline auto xfunction::data_element(size_type i) const -> const_reference { - return data_element_impl(std::make_index_sequence(), i); + return std::apply( + [&](auto&... e) + { + return m_f(e.data_element(i)...); + }, + m_e + ); } template @@ -833,7 +846,13 @@ namespace xt template inline auto xfunction::load_simd(size_type i) const -> simd_return_type { - return load_simd_impl(std::make_index_sequence(), i); + return std::apply( + [&](auto&... e) + { + return m_f.simd_apply((e.template load_simd(i))...); + }, + m_e + ); } template @@ -848,55 +867,6 @@ namespace xt return m_f; } - template - template - inline layout_type xfunction::layout_impl(std::index_sequence) const noexcept - { - return compute_layout(std::get(m_e).layout()...); - } - - template - template - inline auto xfunction::access_impl(std::index_sequence, Args... args) const - -> const_reference - { - XTENSOR_TRY(check_index(shape(), args...)); - XTENSOR_CHECK_DIMENSION(shape(), args...); - return m_f(std::get(m_e)(args...)...); - } - - template - template - inline auto xfunction::unchecked_impl(std::index_sequence, Args... args) const - -> const_reference - { - return m_f(std::get(m_e).unchecked(args...)...); - } - - template - template - inline auto xfunction::element_access_impl(std::index_sequence, It first, It last) const - -> const_reference - { - XTENSOR_TRY(check_element_index(shape(), first, last)); - return m_f((std::get(m_e).element(first, last))...); - } - - template - template - inline auto xfunction::data_element_impl(std::index_sequence, size_type i) const - -> const_reference - { - return m_f((std::get(m_e).data_element(i))...); - } - - template - template - inline auto xfunction::load_simd_impl(std::index_sequence, size_type i) const - { - return m_f.simd_apply((std::get(m_e).template load_simd(i))...); - } - template template inline auto xfunction::build_stepper(Func&& f, std::index_sequence) const noexcept @@ -987,7 +957,13 @@ namespace xt template inline auto xfunction_iterator::operator*() const -> reference { - return deref_impl(std::make_index_sequence()); + return std::apply( + [&](auto&... it) + { + return (p_f->m_f)(*it...); + }, + m_it + ); } template @@ -1010,13 +986,6 @@ namespace xt return std::get(m_it) < std::get(rhs.m_it); } - template - template - inline auto xfunction_iterator::deref_impl(std::index_sequence) const -> reference - { - return (p_f->m_f)(*std::get(m_it)...); - } - template template inline auto xfunction_iterator::tuple_max_diff( @@ -1140,28 +1109,26 @@ namespace xt template inline auto xfunction_stepper::operator*() const -> reference { - return deref_impl(std::make_index_sequence()); - } - - template - template - inline auto xfunction_stepper::deref_impl(std::index_sequence) const -> reference - { - return (p_f->m_f)(*std::get(m_st)...); - } - - template - template - inline auto xfunction_stepper::step_simd_impl(std::index_sequence) -> simd_return_type - { - return (p_f->m_f.simd_apply)(std::get(m_st).template step_simd()...); + return std::apply( + [&](auto&... e) + { + return (p_f->m_f)(*e...); + }, + m_st + ); } template template inline auto xfunction_stepper::step_simd() -> simd_return_type { - return step_simd_impl(std::make_index_sequence()); + return std::apply( + [&](auto&... st) + { + return (p_f->m_f.simd_apply)(st.template step_simd()...); + }, + m_st + ); } template