From abb80cfa4ca961ee1718480e8252ff76bb2dbb2b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 9 May 2022 14:28:27 +0200 Subject: [PATCH] Add operator for concatenating strings and string_views --- src/libutil/util.hh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 09ccfa591..16fa6c54c 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -700,4 +700,19 @@ template overloaded(Ts...) -> overloaded; std::string showBytes(uint64_t bytes); +/* Provide an addition operator between strings and string_views + inexplicably omitted from the standard library. */ +inline std::string operator + (const std::string & s1, std::string_view s2) +{ + auto s = s1; + s.append(s2); + return s; +} + +inline std::string operator + (std::string && s, std::string_view s2) +{ + s.append(s2); + return s; +} + }