The void()
prevents an overloaded operator,
from being called (where one of the parameters is of the type SomeClass<T>
), as such an overload can't have a parameter of type void
.
You will most often see this used in templates, and is used in variadic pack expansions:
// C++11/14:
int unpack[] = {0, (do_something(pack), void(), 0)...};
// C++17 (fold expression):
(void(do_something(pack)), ...);
Where an overloaded operator,
could ruin the sequencing guarantees of the language.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…