toAppend(Tgt* result) {
}
+/**
+ * Variadic base case: do nothing.
+ */
+template <class Delimiter, class Tgt>
+typename std::enable_if<detail::IsSomeString<Tgt>::value>::type
+toAppendDelim(const Delimiter& delim, Tgt* result) {
+}
+
+/**
+ * 1 element: same as toAppend.
+ */
+template <class Delimiter, class T, class Tgt>
+typename std::enable_if<detail::IsSomeString<Tgt>::value>::type
+toAppendDelim(const Delimiter& delim, const T& v, Tgt* tgt) {
+ toAppend(v, tgt);
+}
+
+/**
+ * Append to string with a delimiter in between elements.
+ */
+template <class Delimiter, class T, class... Ts>
+typename std::enable_if<sizeof...(Ts) >= 2
+ && detail::IsSomeString<
+ typename std::remove_pointer<
+ typename std::tuple_element<
+ sizeof...(Ts) - 1, std::tuple<Ts...>
+ >::type>::type>::value>::type
+toAppendDelim(const Delimiter& delim, const T& v, const Ts&... vs) {
+ toAppend(v, delim, detail::getLastElement(vs...));
+ toAppendDelim(delim, vs...);
+}
+
/**
* to<SomeString>(v1, v2, ...) uses toAppend() (see below) as back-end
* for all types.
return result;
}
+/**
+ * toDelim<SomeString>(delim, v1, v2, ...) uses toAppendDelim() as
+ * back-end for all types.
+ */
+template <class Tgt, class Delim, class... Ts>
+typename std::enable_if<detail::IsSomeString<Tgt>::value, Tgt>::type
+toDelim(const Delim& delim, const Ts&... vs) {
+ Tgt result;
+ toAppendDelim(delim, vs..., &result);
+ return result;
+}
+
/*******************************************************************************
* Conversions from string types to integral types.
******************************************************************************/
EXPECT_EQ(s, "Lorem ipsum 1234 dolor amet 567.89.");
}
+template <class String>
+void testVariadicToDelim() {
+ String s;
+ toAppendDelim(":", &s);
+ toAppendDelim(
+ ":", "Lorem ipsum ", 1234, String(" dolor amet "), 567.89, '!', &s);
+ EXPECT_EQ(s, "Lorem ipsum :1234: dolor amet :567.89:!");
+
+ s = toDelim<String>(':');
+ EXPECT_TRUE(s.empty());
+
+ s = toDelim<String>(
+ ":", "Lorem ipsum ", nullptr, 1234, " dolor amet ", 567.89, '.');
+ EXPECT_EQ(s, "Lorem ipsum ::1234: dolor amet :567.89:.");
+}
+
TEST(Conv, NullString) {
string s1 = to<string>((char *) NULL);
EXPECT_TRUE(s1.empty());
testVariadicTo<fbstring>();
}
+TEST(Conv, VariadicToDelim) {
+ testVariadicToDelim<string>();
+ testVariadicToDelim<fbstring>();
+}
+
template <class String>
void testDoubleToString() {
EXPECT_EQ(to<string>(0.0), "0");