I am trying to implement a function that takes a variable number of lines and forwards to a print function that expects a pointer charand sizefor each line alternating.
Example:
std::string a = "123";
std::string b = "1234";
forward(a, b);
I thought the following should be the correct implementation, but despite the fact that it compiles, the behavior is very surprising to me.
template <class ...Args>
void forward(const Args & ... args) {
doPrint( (args.c_str(), args.size())...);
}
forward(a, b)causes doPrint(3, 4), not doPrint("123", 3, "1234", 4)as if I wrote doPrint((args.size())...). The call is c_str()completely ignored by the compiler.
I tried g++, clangand iccwith all the conclusions of the same output. What is wrong with (args.c_str(), args.size())...?
, std::make_tuple(args.c_str(), args.size())... , , , , doPrint, .