Created
April 12, 2018 18:16
-
-
Save loliGothicK/8878edb31a058610b5f4e8fd823bfa6a to your computer and use it in GitHub Desktop.
This file contains 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
int main(){ | |
constexpr auto add_one(int n){ | |
// nがコンパイル時定数ならラムダ式はリテラル型 | |
auto f = [n]{ return n + 1; }; | |
// nがコンパイル時定数ならfはリテラル型なのでgもリテラル型 | |
auto g = [f]{ return f(); }; | |
return g; | |
} | |
static_assert( add_one(1)() == 2 ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment