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
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.
* Whitespace means any of [' ', '\n', '\r', '\t'].
join("_", { "", "f", "a", "c", "e", "b", "o", "o", "k", "" }, output);
EXPECT_EQ(output, "_f_a_c_e_b_o_o_k_");
+
+ output = join("", input3.begin(), input3.end());
+ EXPECT_EQ(output, "facebook");
}
TEST(String, hexlify) {