From: Vsevolod Stakhov Date: Fri, 16 Jul 2021 11:23:00 +0000 (+0100) Subject: [Minor] Add method to make string view from iterators pair X-Git-Tag: 3.0~150 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2385d8976a40183a00bdb759c1b150dee073ec53;p=rspamd.git [Minor] Add method to make string view from iterators pair --- diff --git a/src/libutil/cxx/util.hxx b/src/libutil/cxx/util.hxx index 11c134d1f..8011f67a1 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