Since C++17, we have std::string_view
, a light-weight view into a contiguous sequence of characters that avoids unnecessary copying of data. Instead of having a const std::string&
parameter, it is now often recommended to use std::string_view
.
However, one quickly finds out that switching from const std::string&
to std::string_view
breaks code that uses string concatenation as there is no support for concatenating std::string
and std::string_view
:
std::string{"abc"} + std::string_view{"def"}; // ill-formed (fails to compile)
std::string_view{"abc"} + std::string{"def"}; // ill-formed (fails to compile)
Why is there no support for concatenating std::string
and std::string_view
in the standard?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…