Commit a33734e4 authored by Andrew Chalfant's avatar Andrew Chalfant Committed by JoelMarcey

Add convenience method for folly::join

Summary: While folly has join methods that return a string (and thus don't need a string referenced passed), it does not support this idiom with iterators. This diff adds support for calls like folly::join("/", itr.begin(), itr.end() - 1).

Test Plan: Unit test

Reviewed By: njormrod@fb.com

Subscribers: philipp, trunkagent, njormrod, folly-diffs@, yfeldblum

FB internal diff: D1702892

Tasks: 5691439

Signature: t1:1702892:1418344206:9c1736f5d8e41be1df71a415e3803fe846b387b7
parent 430a2ed1
...@@ -523,6 +523,17 @@ std::string join(const Delim& delimiter, ...@@ -523,6 +523,17 @@ std::string join(const Delim& delimiter,
return output; return output;
} }
template <class Delim,
class Iterator,
typename std::enable_if<std::is_same<
typename std::iterator_traits<Iterator>::iterator_category,
std::random_access_iterator_tag>::value>::type* = nullptr>
std::string join(const Delim& delimiter, Iterator begin, Iterator end) {
std::string output;
join(delimiter, begin, end, output);
return output;
}
/** /**
* Returns a subpiece with all whitespace removed from the front of @sp. * Returns a subpiece with all whitespace removed from the front of @sp.
* Whitespace means any of [' ', '\n', '\r', '\t']. * Whitespace means any of [' ', '\n', '\r', '\t'].
......
...@@ -1072,6 +1072,9 @@ TEST(String, join) { ...@@ -1072,6 +1072,9 @@ TEST(String, join) {
join("_", { "", "f", "a", "c", "e", "b", "o", "o", "k", "" }, output); join("_", { "", "f", "a", "c", "e", "b", "o", "o", "k", "" }, output);
EXPECT_EQ(output, "_f_a_c_e_b_o_o_k_"); EXPECT_EQ(output, "_f_a_c_e_b_o_o_k_");
output = join("", input3.begin(), input3.end());
EXPECT_EQ(output, "facebook");
} }
TEST(String, hexlify) { TEST(String, hexlify) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment