Skip to content

Commit 2c23516

Browse files
committed
[string_view] disambiguate comparisons between std::string_view and rsl::string_view
1 parent 41f054e commit 2c23516

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

include/rsl/string_view

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ template <std::ranges::contiguous_range R>
310310
basic_string_view(R&&) -> basic_string_view<std::ranges::range_value_t<R>>;
311311

312312
// [string.view.comparison], non-member comparison functions
313+
template <typename CharT, typename Traits>
314+
constexpr bool operator==(basic_string_view<CharT, Traits> lhs, std::basic_string_view<CharT, Traits> rhs) noexcept {
315+
// this is a better match for comparisons of rsl::string_view to std::string_view, it disambiguates
316+
return std::string_view(lhs) == rhs;
317+
}
318+
313319
template <typename CharT, typename Traits>
314320
constexpr bool operator==(basic_string_view<CharT, Traits> lhs,
315321
std::type_identity_t<basic_string_view<CharT, Traits>> rhs) noexcept {
@@ -319,6 +325,13 @@ constexpr bool operator==(basic_string_view<CharT, Traits> lhs,
319325
return lhs.compare(rhs) == 0;
320326
}
321327

328+
template <typename CharT, typename Traits>
329+
constexpr auto operator<=>(basic_string_view<CharT, Traits> lhs,
330+
std::basic_string_view<CharT, Traits> rhs) noexcept {
331+
// better match for comparisons between rsl::string_view and std::string_view
332+
return std::string_view(lhs) <=> rhs;
333+
}
334+
322335
template <typename CharT, typename Traits>
323336
constexpr auto operator<=>(basic_string_view<CharT, Traits> lhs,
324337
std::type_identity_t<basic_string_view<CharT, Traits>> rhs) noexcept {

0 commit comments

Comments
 (0)