I am using a fold expression to print elements in a variadic pack, but how do I get a space in between each element?
Currently the output is \"1 234\", the desired outpu
You can reuse print()
to achieve this behaviour. Afterall you are doing a fold
operation which is by definition resursive.
Live Demo
template
struct List
{
static void print_()
{
std::cout<::print();
}
};
If you want to process many elements this way you might run into problems with template depth (gcc for instance has a limit of 900
). Lucky for you you can use the -ftemplate-depth=
option to tweak this behaviour.
You can compile with -ftemplate-depth=100000
and make it work. Note that compilation time will skyrocket (most likely) or in thhe worst case you run out of memory.