From: Philip Pronin Date: Wed, 15 Aug 2012 20:52:40 +0000 (-0700) Subject: one more folly::join overload X-Git-Tag: v0.22.0~1206 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2bfec0de99d40ef333c21d9388952fcd2abd09b0;p=folly.git one more folly::join overload Summary: To allow codemod changes. Test Plan: ran test Reviewed By: tudorb@fb.com FB internal diff: D549516 --- 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);