Skip to content

Instantly share code, notes, and snippets.

@SF-Zhou
Created November 20, 2019 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SF-Zhou/e9b5ede0a68508e8387649c8e5ee351a to your computer and use it in GitHub Desktop.
Save SF-Zhou/e9b5ede0a68508e8387649c8e5ee351a to your computer and use it in GitHub Desktop.
C++ Code Block Magic
// 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