From c7101d8378ba533cb783178ac1468111ab4c2e3e Mon Sep 17 00:00:00 2001 From: Dascandy Date: Wed, 8 Apr 2026 09:16:08 +0200 Subject: [PATCH 1/4] fix: use std prefix, closes #14 --- include/beman/cstring_view/cstring_view.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/beman/cstring_view/cstring_view.hpp b/include/beman/cstring_view/cstring_view.hpp index 0321b7b..a2fbd90 100644 --- a/include/beman/cstring_view/cstring_view.hpp +++ b/include/beman/cstring_view/cstring_view.hpp @@ -146,8 +146,8 @@ class basic_cstring_view { using iterator = const_iterator; using const_reverse_iterator = std::reverse_iterator; using reverse_iterator = const_reverse_iterator; - using size_type = size_t; - using difference_type = ptrdiff_t; + using size_type = std::size_t; + using difference_type = std::ptrdiff_t; static constexpr size_type npos = size_type(-1); private: From 8da1c6922f50a9f3f2687184e217fee152363c3f Mon Sep 17 00:00:00 2001 From: Dascandy Date: Wed, 8 Apr 2026 09:28:53 +0200 Subject: [PATCH 2/4] fix: remove beman::hash, we should only have std::hash. Fixes #13 --- include/beman/cstring_view/cstring_view.hpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/include/beman/cstring_view/cstring_view.hpp b/include/beman/cstring_view/cstring_view.hpp index a2fbd90..081d3cd 100644 --- a/include/beman/cstring_view/cstring_view.hpp +++ b/include/beman/cstring_view/cstring_view.hpp @@ -84,22 +84,6 @@ using u16cstring_view = basic_cstring_view; using u32cstring_view = basic_cstring_view; using wcstring_view = basic_cstring_view; -// [cstring.view.hash], hash support -template -struct hash; -template <> -struct hash; -#if __cpp_char8_t >= 201811L -template <> -struct hash; -#endif -template <> -struct hash; -template <> -struct hash; -template <> -struct hash; - inline namespace literals { inline namespace cstring_view_literals { #ifndef _MSC_VER @@ -451,6 +435,7 @@ struct std::formatter, charT> { }; #endif +// [cstring.view.hash], hash support template <> struct std::hash { auto operator()(const beman::cstring_view& sv) const noexcept { return std::hash{}(sv); } From 4b6dacaf0b3a30dbce4411ea944058b984c5f8ae Mon Sep 17 00:00:00 2001 From: Dascandy Date: Wed, 8 Apr 2026 09:51:29 +0200 Subject: [PATCH 3/4] fix: use _csv prefix consistently, fixes #12 --- include/beman/cstring_view/cstring_view.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/beman/cstring_view/cstring_view.hpp b/include/beman/cstring_view/cstring_view.hpp index 081d3cd..75be5d1 100644 --- a/include/beman/cstring_view/cstring_view.hpp +++ b/include/beman/cstring_view/cstring_view.hpp @@ -98,13 +98,13 @@ inline namespace cstring_view_literals { #pragma warning(disable : 4455) #endif // [cstring.view.literals], suffix for basic_cstring_view literals -constexpr cstring_view operator"" csv(const char* str, size_t len) noexcept; +constexpr cstring_view operator""_csv(const char* str, size_t len) noexcept; #if __cpp_char8_t >= 201811L -constexpr u8cstring_view operator"" csv(const char8_t* str, size_t len) noexcept; +constexpr u8cstring_view operator""_csv(const char8_t* str, size_t len) noexcept; #endif -constexpr u16cstring_view operator"" csv(const char16_t* str, size_t len) noexcept; -constexpr u32cstring_view operator"" csv(const char32_t* str, size_t len) noexcept; -constexpr wcstring_view operator"" csv(const wchar_t* str, size_t len) noexcept; +constexpr u16cstring_view operator""_csv(const char16_t* str, size_t len) noexcept; +constexpr u32cstring_view operator""_csv(const char32_t* str, size_t len) noexcept; +constexpr wcstring_view operator""_csv(const wchar_t* str, size_t len) noexcept; #ifndef _MSC_VER #pragma GCC diagnostic pop #else From e7501031fd23fce6f853284841a96d5b9146550a Mon Sep 17 00:00:00 2001 From: Dascandy Date: Wed, 8 Apr 2026 14:25:24 +0200 Subject: [PATCH 4/4] fix: move comparisons to hidden friends, fixes #24 --- include/beman/cstring_view/cstring_view.hpp | 108 +++++------------- .../beman/cstring_view/cstring_view.test.cpp | 1 + 2 files changed, 29 insertions(+), 80 deletions(-) diff --git a/include/beman/cstring_view/cstring_view.hpp b/include/beman/cstring_view/cstring_view.hpp index 75be5d1..01371cf 100644 --- a/include/beman/cstring_view/cstring_view.hpp +++ b/include/beman/cstring_view/cstring_view.hpp @@ -18,18 +18,6 @@ namespace beman { -namespace detail { - -template -struct type_identity { - using type = T; -}; - -template -using type_identity_t = typename type_identity::type; - -} // namespace detail - // [cstring.view.template], class template basic_cstring_view template > class basic_cstring_view; // partially freestanding @@ -43,33 +31,6 @@ namespace ranges { } #endif */ -// [cstring.view.comparison], non-member comparison functions -template -constexpr bool operator==(basic_cstring_view x, - detail::type_identity_t> y) noexcept; - -#if __cpp_lib_three_way_comparison -template -constexpr auto operator<=>(basic_cstring_view x, - detail::type_identity_t> y) noexcept; -#else -template -constexpr bool operator!=(basic_cstring_view x, - detail::type_identity_t> y) noexcept; -template -constexpr bool operator<(basic_cstring_view x, - detail::type_identity_t> y) noexcept; -template -constexpr bool operator>(basic_cstring_view x, - detail::type_identity_t> y) noexcept; -template -constexpr bool operator<=(basic_cstring_view x, - detail::type_identity_t> y) noexcept; -template -constexpr bool operator>=(basic_cstring_view x, - detail::type_identity_t> y) noexcept; -#endif - // [cstring.view.io], inserters and extractors template std::basic_ostream& operator<<(std::basic_ostream& os, @@ -344,6 +305,34 @@ class basic_cstring_view { return std::basic_string_view(*this).find_last_not_of(s, pos); } +#if __cpp_lib_three_way_comparison + friend constexpr bool operator==(basic_cstring_view x, basic_cstring_view y) noexcept { + return std::basic_string_view(x) == std::basic_string_view(y); + } + friend constexpr auto operator<=>(basic_cstring_view x, basic_cstring_view y) noexcept { + return std::basic_string_view(x) <=> std::basic_string_view(y); + } +#else + friend constexpr bool operator==(basic_cstring_view x, basic_cstring_view y) noexcept { + return std::basic_string_view(x) == std::basic_string_view(y); + } + friend constexpr bool operator!=(basic_cstring_view x, basic_cstring_view y) noexcept { + return std::basic_string_view(x) != std::basic_string_view(y); + } + friend constexpr bool operator<(basic_cstring_view x, basic_cstring_view y) noexcept { + return std::basic_string_view(x) < std::basic_string_view(y); + } + friend constexpr bool operator>(basic_cstring_view x, basic_cstring_view y) noexcept { + return std::basic_string_view(x) > std::basic_string_view(y); + } + friend constexpr bool operator<=(basic_cstring_view x, basic_cstring_view y) noexcept { + return std::basic_string_view(x) <= std::basic_string_view(y); + } + friend constexpr bool operator>=(basic_cstring_view x, basic_cstring_view y) noexcept { + return std::basic_string_view(x) >= std::basic_string_view(y); + } +#endif + private: const_pointer data_; // exposition only size_type size_; // exposition only @@ -370,47 +359,6 @@ constexpr wcstring_view operator""_csv(const wchar_t* str, size_t len) noexcept } // namespace cstring_view_literals } // namespace literals -template -constexpr bool operator==(basic_cstring_view x, - detail::type_identity_t> y) noexcept { - return std::basic_string_view(x) == std::basic_string_view(y); -} - -#if __cpp_lib_three_way_comparison -template -constexpr auto operator<=>(basic_cstring_view x, - detail::type_identity_t> y) noexcept { - return std::basic_string_view(x) <=> std::basic_string_view(y); -} -#else -template -constexpr bool operator!=(basic_cstring_view x, - detail::type_identity_t> y) noexcept { - return std::basic_string_view(x) != std::basic_string_view(y); -} -// Definitions -template -constexpr bool operator<(basic_cstring_view x, - detail::type_identity_t> y) noexcept { - return std::basic_string_view(x) < std::basic_string_view(y); -} -template -constexpr bool operator>(basic_cstring_view x, - detail::type_identity_t> y) noexcept { - return std::basic_string_view(x) > std::basic_string_view(y); -} -template -constexpr bool operator<=(basic_cstring_view x, - detail::type_identity_t> y) noexcept { - return std::basic_string_view(x) <= std::basic_string_view(y); -} -template -constexpr bool operator>=(basic_cstring_view x, - detail::type_identity_t> y) noexcept { - return std::basic_string_view(x) >= std::basic_string_view(y); -} -#endif - template std::basic_ostream& operator<<(std::basic_ostream& os, basic_cstring_view str) { diff --git a/tests/beman/cstring_view/cstring_view.test.cpp b/tests/beman/cstring_view/cstring_view.test.cpp index cba0ebd..7e48df3 100644 --- a/tests/beman/cstring_view/cstring_view.test.cpp +++ b/tests/beman/cstring_view/cstring_view.test.cpp @@ -17,6 +17,7 @@ TEST(StringView, ConstructionDestruction) { EXPECT_NE(h1.c_str(), s.c_str()); EXPECT_TRUE(h1 == h2); EXPECT_TRUE(h1 == s); + EXPECT_TRUE(s == h1); #if __cpp_lib_starts_ends_with >= 201711L EXPECT_TRUE(h1.starts_with("he")); EXPECT_TRUE(h1.ends_with("lo"));