From 411d7d5c50f18bb2db21d13c1328a0c45bbcedaa Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 28 May 2024 09:41:25 +0200 Subject: [PATCH] feat: custom implementation of `swap_ranges` added --- src/core/include/mp-units/ext/algorithm.h | 14 ++++++++++++++ src/core/include/mp-units/ext/fixed_string.h | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/include/mp-units/ext/algorithm.h b/src/core/include/mp-units/ext/algorithm.h index 3aa460b8..4e9f77c0 100644 --- a/src/core/include/mp-units/ext/algorithm.h +++ b/src/core/include/mp-units/ext/algorithm.h @@ -131,4 +131,18 @@ constexpr OutputIt copy(InputIt first, InputIt last, OutputIt d_first) return d_first; } +template +constexpr void iter_swap(ForwardIt1 a, ForwardIt2 b) +{ + using std::swap; + swap(*a, *b); +} + +template +constexpr ForwardIt2 swap_ranges(ForwardIt1 first1, ForwardIt1 last1, ForwardIt2 first2) +{ + for (; first1 != last1; ++first1, ++first2) iter_swap(first1, first2); + return first2; +} + } // namespace mp_units::detail diff --git a/src/core/include/mp-units/ext/fixed_string.h b/src/core/include/mp-units/ext/fixed_string.h index 05c12f4e..1b1d13cf 100644 --- a/src/core/include/mp-units/ext/fixed_string.h +++ b/src/core/include/mp-units/ext/fixed_string.h @@ -141,7 +141,7 @@ public: } // modifiers - constexpr void swap(basic_fixed_string& s) noexcept { std::swap_ranges(begin(), end(), s.begin()); } + constexpr void swap(basic_fixed_string& s) noexcept { swap_ranges(begin(), end(), s.begin()); } // string operations [[nodiscard]] constexpr const_pointer c_str() const noexcept { return data(); }