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 all commits
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
12 changes: 12 additions & 0 deletions src/google/protobuf/stubs/stringpiece.h
Expand Up @@ -148,6 +148,10 @@
#include <limits>
#include <string>

#if defined(__cpp_lib_string_view)
#include <string_view>
#endif

#include <google/protobuf/stubs/hash.h>

#include <google/protobuf/port_def.inc>
Expand Down Expand Up @@ -215,6 +219,14 @@ class PROTOBUF_EXPORT StringPiece {
length_ = CheckSize(str.size());
}

#if defined(__cpp_lib_string_view)
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());
}
#endif

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

Expand Down