As per the C++17 book from "Nicolai M. Josuttis" the following code should compile.
#include <string_view>
#include <string>
int main()
{
std::string_view sv1 = "hello";
std::string_view sv2 = "world";
auto s = std::string(sv1) + sv2;
}
I get the following error (edited for clarity)
test.cpp: In function ‘int main()’:
test.cpp:7:28: error: no match for ‘operator+’ (operand types are ‘std::string’ and ‘std::string_view’)
7 | auto s = std::string(sv1) + sv2;
| ~~~~~~~~~~~ ^ ~~~
| | |
| | std::string_view {aka std::basic_string_view<char>}
| std::string {aka std::basic_string<char>}
In file included from /usr/lib/gcc/x86_64-pc-cygwin/9.3.0/include/c++/bits/stl_algobase.h:67,
from /usr/lib/gcc/x86_64-pc-cygwin/9.3.0/include/c++/bits/char_traits.h:39,
from /usr/lib/gcc/x86_64-pc-cygwin/9.3.0/include/c++/string_view:42,
from test.cpp:1: