[PATCH] D73640: [SmallString] Add explicit conversion to std::string
Jonas Devlieghere via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 10:17:43 PST 2020
This revision was automatically updated to reflect the committed changes.
JDevlieghere marked an inline comment as done.
Closed by commit rGd7049213d0fc: [SmallString] Add explicit conversion to std::string (authored by JDevlieghere).
Changed prior to commit:
https://reviews.llvm.org/D73640?vs=241196&id=241213#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73640/new/
https://reviews.llvm.org/D73640
Files:
llvm/include/llvm/ADT/SmallString.h
llvm/unittests/ADT/SmallStringTest.cpp
Index: llvm/unittests/ADT/SmallStringTest.cpp
===================================================================
--- llvm/unittests/ADT/SmallStringTest.cpp
+++ llvm/unittests/ADT/SmallStringTest.cpp
@@ -96,6 +96,20 @@
EXPECT_STREQ("abcabc", theString.c_str());
}
+TEST_F(SmallStringTest, StringRefConversion) {
+ StringRef abc = "abc";
+ theString.assign(abc.begin(), abc.end());
+ StringRef theStringRef = theString;
+ EXPECT_EQ("abc", theStringRef);
+}
+
+TEST_F(SmallStringTest, StdStringConversion) {
+ StringRef abc = "abc";
+ theString.assign(abc.begin(), abc.end());
+ std::string theStdString = std::string(theString);
+ EXPECT_EQ("abc", theStdString);
+}
+
TEST_F(SmallStringTest, Substr) {
theString = "hello";
EXPECT_EQ("lo", theString.substr(3));
Index: llvm/include/llvm/ADT/SmallString.h
===================================================================
--- llvm/include/llvm/ADT/SmallString.h
+++ llvm/include/llvm/ADT/SmallString.h
@@ -275,6 +275,8 @@
/// Implicit conversion to StringRef.
operator StringRef() const { return str(); }
+ explicit operator std::string() const { return str().str(); }
+
// Extra operators.
const SmallString &operator=(StringRef RHS) {
this->clear();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73640.241213.patch
Type: text/x-patch
Size: 1242 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200129/d7698e33/attachment.bin>
More information about the llvm-commits
mailing list