From b0ac349f706db3194cae90e27ea2139284d08401 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 21 Oct 2020 10:23:04 +1000 Subject: [PATCH] string: fancy comparators should take only string_views This reduces complications dealing with implicit casts from things like 'std::string' which are fairly common. --- string.hpp | 17 ++--------------- test/string.cpp | 9 --------- 2 files changed, 2 insertions(+), 24 deletions(-) diff --git a/string.hpp b/string.hpp index a1bf4bbb..95077107 100644 --- a/string.hpp +++ b/string.hpp @@ -302,10 +302,9 @@ namespace cruft::string::compare { /// \tparam TransformV A character transform function template struct transform { - template bool operator() ( - ContainerT const &a, - ContainerT const &b + std::string_view const &a, + std::string_view const &b ) const noexcept { if (a.size () != b.size ()) return false; @@ -316,18 +315,6 @@ namespace cruft::string::compare { return true; } - - - template < - typename CharT, - typename = std::void_t< - typename std::char_traits::char_type - > - > - bool operator() (CharT const *a, CharT const *b) const noexcept - { - return (*this) (std::string_view (a), std::string_view (b)); - } }; using lower = transform; diff --git a/test/string.cpp b/test/string.cpp index fe33e714..f3b46959 100644 --- a/test/string.cpp +++ b/test/string.cpp @@ -210,15 +210,6 @@ void test_comparator_lower (cruft::TAP::logger &tap) for (auto const &t: TESTS) { tap.expect_eq (cmp (t.a, t.b), t.equal, "compare::lower, pointers, %!", t.message); - tap.expect_eq ( - cmp ( - cruft::view (t.a), - cruft::view (t.b) - ), - t.equal, - "compare::lower, views, %!", - t.message - ); } }