From 4fb93cd82d59dbe17876517baf6285dd37523a41 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Fri, 5 Jul 2024 01:56:16 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20gucc:=20add=20helper=20functions?= =?UTF-8?q?=20for=20indexing=20viewable=20ranges?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gucc/include/gucc/string_utils.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gucc/include/gucc/string_utils.hpp b/gucc/include/gucc/string_utils.hpp index 96a0884..d9e8927 100644 --- a/gucc/include/gucc/string_utils.hpp +++ b/gucc/include/gucc/string_utils.hpp @@ -89,6 +89,16 @@ constexpr auto contains(string_findable auto const& str, std::string_view needle return str.find(needle) != str_type::npos; } +template +constexpr auto index_viewable_range(R&& rng, ranges::range_difference_t n) noexcept { + return ranges::next(ranges::begin(rng), n); +} + +template +constexpr auto size_viewable_range(R&& rng) noexcept { + return ranges::distance(ranges::begin(rng), ranges::end(rng)); +} + } // namespace gucc::utils #endif // STRING_UTILS_HPP