template<class...Fs> void do_in_order(Fs&&...fs) { int _[]={0, ( std::forward<Fs>(fs)(), void(), 0 )...}; (void)_; }
hides the syntax needed to execute a package of function objects in order from left to right.
Then:
struct Bar { template <class... Ts> void foo() { do_in_order([&]{ using T = Ts;
and in the corresponding compiler we will run // code with T , each of which is from left to right.
Please note that some compilers claiming to be C ++ 11 compilers may not compile the above.
The advantage of this method is that it hides the nasty "deploy and evaluate templates" code inside a function with a clear name. You write do_in_order once, and this is usually enough for almost any use of the array expansion trick.
There are two important reasons to use this type of esoteric syntax instead of the โsimplerโ recursive solutions.
Firstly, it facilitates the work of the optimizer. Optimizers sometimes fail after a bunch of recursive calls.
Secondly, the sum of the names of the lengths of functions of function signatures for traditional recursive functions increases with O (n ^ 2). If you use helper types, the total length of the names is also O (n ^ 2). If you are not careful, this can lead to compilation time, connection time, and bloating of binary size.
In C ++ 1z, there are plans for some kind of "fold" syntax that can make esoteric parts higher than less esoteric ones.
Yakk
source share