Commit de064c41 authored by Chip Turner's avatar Chip Turner Committed by Sara Golemon

Add initializer_list support to folly::join

Summary:
Apparently the templates don't like to match the initlializer
list, so this needed to be added.  This allows for things like:

auto s = join(":", {val1, val2, val3, val4, val4});

Test Plan: run tests

Reviewed By: andrei.alexandrescu@fb.com

FB internal diff: D878032
parent b5a0a9f7
......@@ -443,6 +443,13 @@ void join(const Delim& delimiter,
join(delimiter, container.begin(), container.end(), output);
}
template <class Delim, class Value, class String>
void join(const Delim& delimiter,
const std::initializer_list<Value>& values,
String& output) {
join(delimiter, values.begin(), values.end(), output);
}
template <class Delim, class Container>
std::string join(const Delim& delimiter,
const Container& container) {
......@@ -451,6 +458,14 @@ std::string join(const Delim& delimiter,
return output;
}
template <class Delim, class Value>
std::string join(const Delim& delimiter,
const std::initializer_list<Value>& values) {
std::string output;
join(delimiter, values.begin(), values.end(), output);
return output;
}
} // namespace folly
// Hash functions for string and fbstring usable with e.g. hash_map
......
......@@ -823,6 +823,9 @@ TEST(String, join) {
auto input3 = { 'f', 'a', 'c', 'e', 'b', 'o', 'o', 'k' };
join("", input3, output);
EXPECT_EQ(output, "facebook");
join("_", { "", "f", "a", "c", "e", "b", "o", "o", "k", "" }, output);
EXPECT_EQ(output, "_f_a_c_e_b_o_o_k_");
}
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