commit 2385d89: [Minor] Add method to make string view from iterators pair
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Jul 16 11:28:04 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-07-16 12:23:00 +0100
URL: https://github.com/rspamd/rspamd/commit/2385d8976a40183a00bdb759c1b150dee073ec53
[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 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<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
More information about the Commits
mailing list