I was reading about folding expressions and found an example of what was used before folding expressions:
template <class... Ts>
void print_all(std::ostream& os, Ts const&... args) {
using expander = int[];
(void)expander{0,
(void(os << args), 0)...
};
}
The problem is the void(os << args)
bit. What does void mean in this context? I've already tried to search for this, but it is pretty generic.
Thanks for your time.
void* is a "pointer to anything". void ** is another level of indirection - "pointer to pointer to anything". Basically, you pass that in when you want to allow the function to return a pointer of any type.
When used as a function return type, the void keyword specifies that the function doesn't return a value. When used for a function's parameter list, void specifies that the function takes no parameters.
It casts the result of (os << args)
to void
. That's it.
This style is used to prevent the very rare overload of ,
(comma) operator since in theory, <<
can be overloaded for user-defined args
argument and return something that has overloaded the comma operator for X, 0
expression. That might break the initialization trick. This way, the code is safe and comma is always used as the ordinary sequencing operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With