Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3540)

Unified Diff: base/strings/string_piece.h

Issue 2758163003: Use string(StringPiece) instead of StringPiece::as_string(). (Closed)
Patch Set: Add StringPiece unittests. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/strings/string_piece_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/strings/string_piece.h
diff --git a/base/strings/string_piece.h b/base/strings/string_piece.h
index eaec14de5da788ebab2137df35015b9998ec892e..5333640fee3399441a62439011679f402824c6b1 100644
--- a/base/strings/string_piece.h
+++ b/base/strings/string_piece.h
@@ -245,6 +245,9 @@ template <typename STRING_TYPE> class BasicStringPiece {
return r;
}
+ // This is the style of conversion preferred by std::string_view in C++17.
+ explicit operator STRING_TYPE() const { return as_string(); }
+
STRING_TYPE as_string() const {
// std::string doesn't like to take a NULL pointer even with a 0 size.
return empty() ? STRING_TYPE() : STRING_TYPE(data(), size());
« no previous file with comments | « no previous file | base/strings/string_piece_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698