Last active
August 27, 2020 13:02
-
-
Save talybin/13d595eb17b0c4142cc4c38eed31a7ee to your computer and use it in GitHub Desktop.
Lambda closure decomposition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| template <class T> struct overload : T { using T::operator(); }; | |
| template <class T> overload(T) -> overload<T>; | |
| int main() | |
| { | |
| auto f = [x = 1, y = 2]() { return x + y; }; | |
| // auto [a, b] = f; // error: cannot decompose lambda closure type 'main()::<lambda()>' | |
| overload o { f }; | |
| auto [a, b] = o; | |
| std::cout << "a: " << a << '\n'; | |
| std::cout << "b: " << b << '\n'; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment