Compiling with gcc-7.1 with the flag -std=c++17
, the following program raises an error:
#include <string_view>
void foo(const char* cstr) {}
void bar(std::string_view str){
foo(str);
}
The error message is
In function 'void bar(std::string_view)':
error: cannot convert 'std::string_view {aka std::basic_string_view<char>}' to 'const char*' for argument '1' to 'void foo(const char*)'
foo(str);
I'm surprised there is no conversion to const char*
because other libraries (abseil, bde), provide similar string_view
classes which implicitly convert to const char*
.