Skip to content

Instantly share code, notes, and snippets.

@loliGothicK
Created April 12, 2018 18:16
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 loliGothicK/8878edb31a058610b5f4e8fd823bfa6a to your computer and use it in GitHub Desktop.
Save loliGothicK/8878edb31a058610b5f4e8fd823bfa6a to your computer and use it in GitHub Desktop.
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