From 700f6ad1423e78936c8250a4e18fe8aeb0f75927 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Tue, 21 Mar 2017 19:35:05 +0000 Subject: [PATCH] [ADT] Add a version of llvm::join() that takes a range. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298427 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/StringExtras.h | 7 +++++++ unittests/ADT/StringRefTest.cpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/include/llvm/ADT/StringExtras.h b/include/llvm/ADT/StringExtras.h index 488748a5f60..8214782bfe8 100644 --- a/include/llvm/ADT/StringExtras.h +++ b/include/llvm/ADT/StringExtras.h @@ -234,6 +234,13 @@ inline std::string join(IteratorT Begin, IteratorT End, StringRef Separator) { return detail::join_impl(Begin, End, Separator, tag()); } +/// Joins the strings in the range [R.begin(), R.end()), adding Separator +/// between the elements. +template +inline std::string join(Range &&R, StringRef Separator) { + return join(R.begin(), R.end(), Separator); +} + /// Joins the strings in the parameter pack \p Items, adding \p Separator /// between the elements. All arguments must be implicitly convertible to /// std::string, or there should be an overload of std::string::operator+=() diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index 614ec5d59e6..bd9387837df 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -899,6 +899,8 @@ TEST(StringRefTest, joinStrings) { EXPECT_TRUE(v2_join2); bool v2_join3 = join(v2.begin(), v2.end(), "::") == join_result3; EXPECT_TRUE(v2_join3); + v2_join3 = join(v2, "::") == join_result3; + EXPECT_TRUE(v2_join3); } -- 2.40.0