I would like to create a CSV list using a variadic function.
Being a lazy programmer, it would be nice to have it be a one-liner, and fold expressions look like they might fit the bill.
The following code does not work:
template<typename ...T>
std::string MakeCSV(T&... args) {
std::stringstream ss;
(ss << args << "," << ...);
return ss.str();
}
int main() {
std::string s1 = "one";
std::string s2 = "two";
std::cout << MakeCSV(s1, s2) << std::endl;
return 0;
}
This gives:
error: binary expression in operand of fold-expression
(ss << args << "," << ...);
~~~~~~~~~~~^~~~~~
How do I add extra parameters to a fold expression in addition to the input list itself?