[llvm] r298427 - [ADT] Add a version of llvm::join() that takes a range.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 21 12:35:06 PDT 2017
Author: zturner
Date: Tue Mar 21 14:35:05 2017
New Revision: 298427
URL: http://llvm.org/viewvc/llvm-project?rev=298427&view=rev
Log:
[ADT] Add a version of llvm::join() that takes a range.
Modified:
llvm/trunk/include/llvm/ADT/StringExtras.h
llvm/trunk/unittests/ADT/StringRefTest.cpp
Modified: llvm/trunk/include/llvm/ADT/StringExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringExtras.h?rev=298427&r1=298426&r2=298427&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/StringExtras.h Tue Mar 21 14:35:05 2017
@@ -234,6 +234,13 @@ inline std::string join(IteratorT Begin,
return detail::join_impl(Begin, End, Separator, tag());
}
+/// Joins the strings in the range [R.begin(), R.end()), adding Separator
+/// between the elements.
+template <typename Range>
+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+=()
Modified: llvm/trunk/unittests/ADT/StringRefTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringRefTest.cpp?rev=298427&r1=298426&r2=298427&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/StringRefTest.cpp (original)
+++ llvm/trunk/unittests/ADT/StringRefTest.cpp Tue Mar 21 14:35:05 2017
@@ -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);
}
More information about the llvm-commits
mailing list