Add operator for concatenating strings and string_views

This commit is contained in:
Eelco Dolstra 2022-05-09 14:28:27 +02:00
parent 24b3a500a7
commit abb80cfa4c
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE

View file

@ -700,4 +700,19 @@ template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
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;
}
}