From 0b5ac0d987c15299e2d7bb842751ecc25c327e73 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Sat, 13 Jul 2024 00:11:47 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20gucc:=20use=20contains=20member?= =?UTF-8?q?=20from=20C++23=20instead?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gucc/include/gucc/string_utils.hpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gucc/include/gucc/string_utils.hpp b/gucc/include/gucc/string_utils.hpp index d9e8927..c678586 100644 --- a/gucc/include/gucc/string_utils.hpp +++ b/gucc/include/gucc/string_utils.hpp @@ -75,18 +75,14 @@ constexpr auto make_split_view(std::string_view str, char delim = '\n') noexcept | ranges::views::filter(second); } -template > +template concept string_findable = requires(T value) { - // check that type of T::npos is T::size_type - { npos_type{} } -> std::same_as; - // check that type of T::find is T::size_type - { value.find(std::string_view{""}) } -> std::same_as; + // check that type of T::contains is bool + { value.contains(std::string_view{""}) } -> std::same_as; }; - // simple helper function to check if string contains a string constexpr auto contains(string_findable auto const& str, std::string_view needle) noexcept -> bool { - using str_type = std::remove_reference_t; - return str.find(needle) != str_type::npos; + return str.contains(needle); } template