次のコード スニペットを検討してください。
template <typename TF>
void post(TF){ }
template <typename... TFs>
struct funcs : TFs...
{
funcs(TFs... fs) : TFs{fs}... { }
void call()
{
(post([&]{ static_cast<TFs&>(*this)(); }), ...);
}
};
g++ 7.0は、次のエラーでコンパイルに失敗します:
prog.cc: In lambda function:
prog.cc:10:43: error: parameter packs not expanded with '...':
(post([&]{ static_cast<TFs&>(*this)(); }), ...);
~~~~~~~~~~~~~~~~~~~~~~~~^~
prog.cc:10:43: note: 'TFs'
prog.cc: In member function 'void funcs<TFs>::call()':
prog.cc:10:13: error: operand of fold expression has no unexpanded parameter packs
(post([&]{ static_cast<TFs&>(*this)(); }), ...);
~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
post
呼び出しとラムダを削除すると、 g++ は fold expression をコンパイルします。
ラムダ、フォールド式、およびテンプレート関数呼び出しの間のこの相互作用は、何らかの形で標準によって禁止されていますか、それとも gcc のバグですか?