diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2020-01-28 13:51:38 +0100 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2020-01-28 13:56:12 +0100 |
commit | 2e4977965b57c53db81e729e390dbda6807ef7fc (patch) | |
tree | 8c2363304ebc728b9943e73d6a10ea72ddb61a1d /llvm/unittests/ADT/StringRefTest.cpp | |
parent | d8de349951c275af86d67eb3e9c7b1f554531a9b (diff) | |
download | llvm-2e4977965b57c53db81e729e390dbda6807ef7fc.zip llvm-2e4977965b57c53db81e729e390dbda6807ef7fc.tar.gz llvm-2e4977965b57c53db81e729e390dbda6807ef7fc.tar.bz2 |
[ADT] Implicitly convert between StringRef and std::string_view when we have C++17
This makes the types almost seamlessly interchangeable in C++17
codebases. Eventually we want to replace StringRef with the standard
type, but that requires C++17 being the default and a huge refactoring
job as StringRef has a lot more functionality.
Diffstat (limited to 'llvm/unittests/ADT/StringRefTest.cpp')
-rw-r--r-- | llvm/unittests/ADT/StringRefTest.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/StringRefTest.cpp b/llvm/unittests/ADT/StringRefTest.cpp index 9cb24bf..fbf2d84 100644 --- a/llvm/unittests/ADT/StringRefTest.cpp +++ b/llvm/unittests/ADT/StringRefTest.cpp @@ -59,6 +59,16 @@ TEST(StringRefTest, Construction) { EXPECT_EQ("hello", StringRef("hello")); EXPECT_EQ("hello", StringRef("hello world", 5)); EXPECT_EQ("hello", StringRef(std::string("hello"))); +#if __cplusplus > 201402L + EXPECT_EQ("hello", StringRef(std::string_view("hello"))); +#endif +} + +TEST(StringRefTest, Conversion) { + EXPECT_EQ("hello", std::string(StringRef("hello"))); +#if __cplusplus > 201402L + EXPECT_EQ("hello", std::string_view(StringRef("hello"))); +#endif } TEST(StringRefTest, EmptyInitializerList) { |