Created
November 20, 2019 03:05
-
-
Save SF-Zhou/e9b5ede0a68508e8387649c8e5ee351a to your computer and use it in GitHub Desktop.
C++ Code Block Magic
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
// Need C++ 11 | |
#include <functional> | |
#include <iostream> | |
class A { | |
public: | |
template <class F> | |
auto operator-(const F &func) -> typename std::result_of<F()>::type { | |
return func(); | |
} | |
}; | |
#define BLOCK A() - [&] | |
int main() { | |
int year = 1994; | |
int age = BLOCK { | |
int now = 2019; | |
return now - year; | |
}; | |
printf("%d\n", age); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment