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

Added absl::string_view constructor from std::string view #1568

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions absl/strings/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@
#include "absl/base/optimization.h"
#include "absl/base/port.h"

#ifdef ABSL_USES_STD_STRING_VIEW

#ifdef ABSL_HAVE_STD_STRING_VIEW
#include <string_view> // IWYU pragma: export
#endif

#ifdef ABSL_USES_STD_STRING_VIEW

namespace absl {
ABSL_NAMESPACE_BEGIN
Expand Down Expand Up @@ -201,6 +203,12 @@ class string_view {
constexpr string_view(const char* data, size_type len)
: ptr_(data), length_(CheckLengthInternal(len)) {}

#ifdef ABSL_HAVE_STD_STRING_VIEW
// Implicit constructor from std::string view
constexpr string_view(std::string_view str)
: ptr_(str.data ()), length_(CheckLengthInternal(str.size())) {}
#endif

// NOTE: Harmlessly omitted to work around gdb bug.
// constexpr string_view(const string_view&) noexcept = default;
// string_view& operator=(const string_view&) noexcept = default;
Expand Down