Here is the idiom in question:
template<typename... T>
void f(T... t) {
int temp[] = {(g(t), 0)...};
}
This will be compiled as g(t0); g(t1); ...
, order of function calls is guaranteed by C++11[dcl.init.list]/4.
A better version uses std::initializer_list
instead of array, but it's not important here.
The question is: how should we call this idiom?
Upd:
Basically, it's the idiom which we should advise to people to use it instead of recursion, i.e. to replace two overloadsvoid f() {}
void f(H head, T... tail) { g(head); f(tail...); }
with singlevoid f(T... t) { int temp[]{(g(t), 0)...}; }
Of course we can call it "An idiom which will be replaced by the Fold Expressions" but I hope there is a proper term for it.
Pack expansion.
C++11 §5.1.2/23 in [expr.prim.lambda]:
” A capture followed by an ellipsis is a pack expansion (14.5.3). [Example:
template<class... Args> void f(Args... args) { auto lm = [&, args...] { return g(args...); }; lm(); }
—end example ]
I think that covers it. The pack expansion without applying a function can be viewed as one applying an identity function.
C++11 §14.5.3/4 in [temp.variadic]:
A pack expansion consists of a pattern and an ellipsis, the instantiation of which produces zero or more instantiations of the pattern in a list (described below). […]
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