From 51b1a07a51ecd06f9e3061aab66dd565b25807b1 Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Wed, 10 Apr 2024 00:33:17 +0200 Subject: [PATCH] ``: Throughput improvements (#4559) Co-authored-by: Stephan T. Lavavej --- stl/inc/mdspan | 41 ++++++++++++----------- tests/std/include/test_mdspan_support.hpp | 2 +- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/stl/inc/mdspan b/stl/inc/mdspan index 551f60b493..b6ba7e51c1 100644 --- a/stl/inc/mdspan +++ b/stl/inc/mdspan @@ -218,8 +218,8 @@ public: : extents(_Other, make_index_sequence{}) {} template - requires (is_convertible_v<_OtherIndexTypes, index_type> && ...) - && (is_nothrow_constructible_v && ...) + requires conjunction_v..., + is_nothrow_constructible...> && (sizeof...(_OtherIndexTypes) == rank_dynamic() || sizeof...(_OtherIndexTypes) == rank()) constexpr explicit extents(_OtherIndexTypes... _Exts) noexcept : extents(_Extents_from_tuple{}, _STD tie(_Exts...), make_index_sequence{}) { @@ -305,7 +305,7 @@ public: template _NODISCARD constexpr bool _Contains_multidimensional_index( index_sequence<_Seq...>, _IndexTypes... _Indices) const noexcept { - _STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...)); + _STL_INTERNAL_STATIC_ASSERT(conjunction_v...>); if constexpr (unsigned_integral) { return ((_Indices < extent(_Seq)) && ...); } else { @@ -318,7 +318,7 @@ template constexpr size_t _Repeat_dynamic_extent = dynamic_extent; template - requires (is_convertible_v<_Integrals, size_t> && ...) + requires conjunction_v...> explicit extents(_Integrals...) -> extents...>; template @@ -561,8 +561,9 @@ public: } template - requires (sizeof...(_IndexTypes) == extents_type::rank()) && (is_convertible_v<_IndexTypes, index_type> && ...) - && (is_nothrow_constructible_v && ...) + requires (sizeof...(_IndexTypes) == extents_type::rank()) + && conjunction_v..., + is_nothrow_constructible...> _NODISCARD constexpr index_type operator()(_IndexTypes... _Indices) const noexcept { return _Index_impl(make_index_sequence{}, static_cast(_Indices)...); } @@ -611,7 +612,7 @@ private: template _NODISCARD constexpr index_type _Index_impl( [[maybe_unused]] index_sequence<_Seq...> _Index_seq, _IndexTypes... _Indices) const noexcept { - _STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...)); + _STL_INTERNAL_STATIC_ASSERT(conjunction_v...>); #if _CONTAINER_DEBUG_LEVEL > 0 _STL_VERIFY(this->_Exts._Contains_multidimensional_index(_Index_seq, _Indices...), "Value of extents_type::index-cast(i) must be a multidimensional index in extents_ (N4950 " @@ -713,8 +714,9 @@ public: } template - requires (sizeof...(_IndexTypes) == extents_type::rank()) && (is_convertible_v<_IndexTypes, index_type> && ...) - && (is_nothrow_constructible_v && ...) + requires (sizeof...(_IndexTypes) == extents_type::rank()) + && conjunction_v..., + is_nothrow_constructible...> _NODISCARD constexpr index_type operator()(_IndexTypes... _Indices) const noexcept { return _Index_impl(make_index_sequence{}, static_cast(_Indices)...); } @@ -763,7 +765,7 @@ private: template _NODISCARD constexpr index_type _Index_impl( [[maybe_unused]] index_sequence<_Seq...> _Index_seq, _IndexTypes... _Indices) const noexcept { - _STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...)); + _STL_INTERNAL_STATIC_ASSERT(conjunction_v...>); #if _CONTAINER_DEBUG_LEVEL > 0 _STL_VERIFY(this->_Exts._Contains_multidimensional_index(_Index_seq, _Indices...), "Value of extents_type::index-cast(i) must be a multidimensional index in extents_ (N4950 " @@ -938,8 +940,9 @@ public: } template - requires (sizeof...(_IndexTypes) == extents_type::rank()) && (is_convertible_v<_IndexTypes, index_type> && ...) - && (is_nothrow_constructible_v && ...) + requires (sizeof...(_IndexTypes) == extents_type::rank()) + && conjunction_v..., + is_nothrow_constructible...> _NODISCARD constexpr index_type operator()(_IndexTypes... _Indices) const noexcept { return _Index_impl(make_index_sequence{}, static_cast(_Indices)...); } @@ -1020,7 +1023,7 @@ private: template _NODISCARD constexpr index_type _Index_impl( [[maybe_unused]] index_sequence<_Seq...> _Index_seq, _IndexTypes... _Indices) const noexcept { - _STL_INTERNAL_STATIC_ASSERT((same_as<_IndexTypes, index_type> && ...)); + _STL_INTERNAL_STATIC_ASSERT(conjunction_v...>); #if _CONTAINER_DEBUG_LEVEL > 0 _STL_VERIFY(this->_Exts._Contains_multidimensional_index(_Index_seq, _Indices...), "Value of extents_type::index-cast(i) must be a multidimensional index in extents_ (N4950 " @@ -1215,8 +1218,8 @@ public: constexpr mdspan(mdspan&&) = default; template - requires (is_convertible_v<_OtherIndexTypes, index_type> && ...) - && (is_nothrow_constructible_v && ...) + requires conjunction_v..., + is_nothrow_constructible...> && (sizeof...(_OtherIndexTypes) == rank() || sizeof...(_OtherIndexTypes) == rank_dynamic()) && is_constructible_v && is_default_constructible_v constexpr explicit mdspan(data_handle_type _Ptr_, _OtherIndexTypes... _Exts) noexcept( @@ -1295,8 +1298,8 @@ public: #ifdef __cpp_multidimensional_subscript // TRANSITION, P2128R6 template - requires (is_convertible_v<_OtherIndexTypes, index_type> && ...) - && (is_nothrow_constructible_v && ...) + requires conjunction_v..., + is_nothrow_constructible...> && (sizeof...(_OtherIndexTypes) == rank()) _NODISCARD constexpr reference operator[](_OtherIndexTypes... _Indices) const noexcept(noexcept(_Access_impl(static_cast(_STD move(_Indices))...))) /* strengthened */ { @@ -1427,7 +1430,7 @@ private: template _NODISCARD constexpr reference _Access_impl(_OtherIndexTypes... _Indices) const noexcept(noexcept(this->_Acc.access(_Ptr, static_cast(this->_Map(_Indices...))))) { - _STL_INTERNAL_STATIC_ASSERT((same_as<_OtherIndexTypes, index_type> && ...)); + _STL_INTERNAL_STATIC_ASSERT(conjunction_v...>); #if _CONTAINER_DEBUG_LEVEL > 0 _STL_VERIFY(this->_Map.extents()._Contains_multidimensional_index(make_index_sequence{}, _Indices...), "I must be a multidimensional index in extents() (N4950 [mdspan.mdspan.members]/3)."); @@ -1448,7 +1451,7 @@ template mdspan(_Pointer&&) -> mdspan>, extents>; template - requires ((is_convertible_v<_Integrals, size_t> && ...) && sizeof...(_Integrals) > 0) + requires conjunction_v...> && (sizeof...(_Integrals) > 0) explicit mdspan(_ElementType*, _Integrals...) -> mdspan<_ElementType, dextents>; template diff --git a/tests/std/include/test_mdspan_support.hpp b/tests/std/include/test_mdspan_support.hpp index b9d4a0acf8..cc09948b0a 100644 --- a/tests/std/include/test_mdspan_support.hpp +++ b/tests/std/include/test_mdspan_support.hpp @@ -256,7 +256,7 @@ MappingProperties get_mapping_properties(const Mapping& mapping) { return std::views::cartesian_product(std::views::iota(IndexType{0}, get_extent(Indices))...); }(rank_indices); - auto map_index = [&](const auto& tpl) { return std::apply([&](auto... i) { return mapping(i...); }, tpl); }; + auto map_index = [&](const auto& tpl) { return std::apply(mapping, tpl); }; auto mapped_indices = multidim_indices | std::views::transform(map_index) | std::ranges::to(); std::ranges::sort(mapped_indices);