From 2385d8976a40183a00bdb759c1b150dee073ec53 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 16 Jul 2021 12:23:00 +0100 Subject: [PATCH] [Minor] Add method to make string view from iterators pair --- src/libutil/cxx/util.hxx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libutil/cxx/util.hxx b/src/libutil/cxx/util.hxx index 11c134d1f3..8011f67a12 100644 --- a/src/libutil/cxx/util.hxx +++ b/src/libutil/cxx/util.hxx @@ -91,6 +91,18 @@ constexpr auto find_map(const C &c, const K &k) -> std::optional +inline constexpr auto make_string_view_from_it(_It begin, _It end) +{ + using result_type = std::string_view; + + return result_type{((begin != end) ? &*begin : nullptr), + (typename result_type::size_type)std::max(std::distance(begin, end), + (typename result_type::difference_type)0) + }; +} + } #endif //RSPAMD_UTIL_HXX -- 2.47.3