From 0f06fa98edf60abc1ae0c1657eb359f670f853e4 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 21 May 2026 11:24:48 -0700 Subject: [PATCH] some misc clean-ups of `__static_vector` --- include/stdexec/__detail/__static_vector.hpp | 46 +++++++++++++++----- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/include/stdexec/__detail/__static_vector.hpp b/include/stdexec/__detail/__static_vector.hpp index ae81bc198..0cee07851 100644 --- a/include/stdexec/__detail/__static_vector.hpp +++ b/include/stdexec/__detail/__static_vector.hpp @@ -54,15 +54,27 @@ namespace STDEXEC template [[nodiscard]] - friend constexpr auto operator+(__static_vector<_Ty, _Capacity0> const &__lhs, // - __static_vector<_Ty, _Capacity1> const &__rhs) + friend constexpr auto + operator+([[maybe_unused]] __static_vector<_Ty, _Capacity0> const &__lhs, // + [[maybe_unused]] __static_vector<_Ty, _Capacity1> const &__rhs) noexcept(__nothrow_copy_constructible<_Ty>) -> __static_vector<_Ty, _Capacity0 + _Capacity1> { - __static_vector<_Ty, _Capacity0 + _Capacity1> __result; - std::copy(__lhs.begin(), __lhs.end(), __result.begin()); - std::copy(__rhs.begin(), __rhs.end(), __result.begin() + __lhs.size()); - __result.resize(__lhs.size() + __rhs.size()); - return __result; + if constexpr (_Capacity0 == 0) + { + return __rhs; + } + else if constexpr (_Capacity1 == 0) + { + return __lhs; + } + else + { + __static_vector<_Ty, _Capacity0 + _Capacity1> __result; + std::copy(__lhs.begin(), __lhs.end(), __result.begin()); + std::copy(__rhs.begin(), __rhs.end(), __result.begin() + __lhs.size()); + __result.resize(__lhs.size() + __rhs.size()); + return __result; + } } }; } // namespace __detail @@ -134,13 +146,19 @@ namespace STDEXEC constexpr void resize(std::size_t __new_size) noexcept { + STDEXEC_ASSERT(__new_size <= _Capacity); __size_ = __new_size; } constexpr auto erase(const_iterator __first, const_iterator __last) noexcept -> iterator { - std::move(const_cast(__last), end(), const_cast(__first)); - resize(size() - (__last - __first)); + STDEXEC_ASSERT(__first >= begin() && __first <= end()); + STDEXEC_ASSERT(__last >= __first && __last <= end()); + if (__first != __last) + { + std::move(const_cast(__last), end(), const_cast(__first)); + resize(size() - (__last - __first)); + } return end(); } @@ -207,11 +225,15 @@ namespace STDEXEC return 0; } - constexpr auto erase(const_iterator __first, const_iterator __last) noexcept -> iterator + constexpr void resize([[maybe_unused]] std::size_t __new_size) noexcept { - STDEXEC_ASSERT(__first == __last); - STDEXEC_ASSERT(__first == nullptr); + STDEXEC_ASSERT(__new_size == 0); + } + constexpr auto erase([[maybe_unused]] const_iterator __first, + [[maybe_unused]] const_iterator __last) noexcept -> iterator + { + STDEXEC_ASSERT(__first == __last); return end(); } };