string: fancy comparators should take only string_views
This reduces complications dealing with implicit casts from things like 'std::string' which are fairly common.
This commit is contained in:
parent
8111074a44
commit
b0ac349f70
17
string.hpp
17
string.hpp
@ -302,10 +302,9 @@ namespace cruft::string::compare {
|
||||
/// \tparam TransformV A character transform function
|
||||
template <char (*TransformV)(char) noexcept>
|
||||
struct transform {
|
||||
template <typename ContainerT>
|
||||
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<CharT>::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<ascii::try_lower>;
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user