Skip to content

Commit

Permalink
feat: custom implementation of swap_ranges added
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed May 28, 2024
1 parent 602a609 commit 411d7d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/core/include/mp-units/ext/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,18 @@ constexpr OutputIt copy(InputIt first, InputIt last, OutputIt d_first)
return d_first;
}

template<class ForwardIt1, class ForwardIt2>
constexpr void iter_swap(ForwardIt1 a, ForwardIt2 b)
{
using std::swap;
swap(*a, *b);
}

template<class ForwardIt1, class ForwardIt2>
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
2 changes: 1 addition & 1 deletion src/core/include/mp-units/ext/fixed_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class basic_fixed_string {
}

// 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(); }
Expand Down

0 comments on commit 411d7d5

Please sign in to comment.