Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make StringPiece constructible from std::string_view #8707

Merged
merged 2 commits into from Jun 9, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/google/protobuf/stubs/stringpiece.h
Expand Up @@ -214,6 +214,13 @@ class PROTOBUF_EXPORT StringPiece {
: ptr_(str.data()), length_(0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to fix this one by replacing const string& with std::string_view, but certain cases were broken.

I. e. HasSuffixString(const string&, const string&) stops working as it requires 2 implicit ctors (and the standard only allows one).

This could be simplified with C++20 starts_with / ends_with, but this is a long story.

length_ = CheckSize(str.size());
}

StringPiece( // NOLINT(runtime/explicit)
georgthegreat marked this conversation as resolved.
Show resolved Hide resolved
std::string_view str)
: ptr_(str.data()), length_(0) {
length_ = CheckSize(str.size());
}


StringPiece(const char* offset, size_type len)
: ptr_(offset), length_(CheckSize(len)) {}
Expand Down