From 53869fbd424bcb7002a0bc782b17774091fe69ea 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 de0eb10e9..ea90f60e7 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -706,4 +706,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; +} + }