👷 gucc: add helper functions for indexing viewable ranges

This commit is contained in:
Vladislav Nepogodin 2024-07-05 01:56:16 +04:00
parent 7c75e4600d
commit 4fb93cd82d
No known key found for this signature in database
GPG Key ID: B62C3D10C54D5DA9

View File

@ -89,6 +89,16 @@ constexpr auto contains(string_findable auto const& str, std::string_view needle
return str.find(needle) != str_type::npos; return str.find(needle) != str_type::npos;
} }
template <ranges::viewable_range R>
constexpr auto index_viewable_range(R&& rng, ranges::range_difference_t<R> n) noexcept {
return ranges::next(ranges::begin(rng), n);
}
template <ranges::viewable_range R>
constexpr auto size_viewable_range(R&& rng) noexcept {
return ranges::distance(ranges::begin(rng), ranges::end(rng));
}
} // namespace gucc::utils } // namespace gucc::utils
#endif // STRING_UTILS_HPP #endif // STRING_UTILS_HPP