]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add method to make string view from iterators pair
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Jul 2021 11:23:00 +0000 (12:23 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 16 Jul 2021 11:23:00 +0000 (12:23 +0100)
src/libutil/cxx/util.hxx

index 11c134d1f3b4764a07389d3070c2fe223b4f3630..8011f67a129959970859bf71ebe2b8227c5444c4 100644 (file)
@@ -91,6 +91,18 @@ constexpr auto find_map(const C &c, const K &k) -> std::optional<std::reference_
        return std::nullopt;
 }
 
+
+template <typename _It>
+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