Closed
Description
Compile with -std=c++20
:
template <class>
inline constexpr auto fun =
[]<class... Ts>(Ts... ts) {
return [... us = (Ts&&) ts]<class Fun>(Fun&& fn) mutable {
return static_cast<Fun&&>(fn)(static_cast<Ts&&>(us)...);
};
};
int main() {
auto s = fun<int>(1,2,3,4);
}
Demo on Godbolt: https://godbolt.org/z/Kjq8PEGn1
Result:
<source>:6:58: error: pack expansion contains parameter pack 'Ts' that has a different length (1 vs. 4) from outer parameter packs
return static_cast<Fun&&>(fn)(static_cast<Ts&&>(us)...);
~~ ^
<source>:11:20: note: in instantiation of function template specialization '(anonymous class)::operator()<int, int, int, int>' requested here
auto s = fun<int>(1,2,3,4);
^
1 error generated.
Expected:
Success