From 2bfec0de99d40ef333c21d9388952fcd2abd09b0 Mon Sep 17 00:00:00 2001 From: Philip Pronin Date: Wed, 15 Aug 2012 13:52:40 -0700 Subject: [PATCH] one more folly::join overload Summary: To allow codemod changes. Test Plan: ran test Reviewed By: tudorb@fb.com FB internal diff: D549516 --- folly/String.h | 8 ++++++++ folly/test/StringTest.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/folly/String.h b/folly/String.h index 906a9f37..bd7b0114 100644 --- a/folly/String.h +++ b/folly/String.h @@ -353,6 +353,14 @@ void join(const Delim& delimiter, join(delimiter, container.begin(), container.end(), output); } +template +std::string join(const Delim& delimiter, + const Container& container) { + std::string output; + join(delimiter, container.begin(), container.end(), output); + return output; +} + } // namespace folly // Hash functions for string and fbstring usable with e.g. hash_map diff --git a/folly/test/StringTest.cpp b/folly/test/StringTest.cpp index df5c6891..ec01eb6c 100644 --- a/folly/test/StringTest.cpp +++ b/folly/test/StringTest.cpp @@ -644,10 +644,14 @@ TEST(String, join) { std::vector input1 = { "1", "23", "456", "" }; join(':', input1, output); EXPECT_EQ(output, "1:23:456:"); + output = join(':', input1); + EXPECT_EQ(output, "1:23:456:"); auto input2 = { 1, 23, 456 }; join("-*-", input2, output); EXPECT_EQ(output, "1-*-23-*-456"); + output = join("-*-", input2); + EXPECT_EQ(output, "1-*-23-*-456"); auto input3 = { 'f', 'a', 'c', 'e', 'b', 'o', 'o', 'k' }; join("", input3, output); -- 2.34.1