Last active
April 27, 2018 19:15
-
-
Save loliGothicK/4e9e35b716a9465032567a83887bfd21 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
template <class F> | |
struct Fixed { | |
F f; | |
template <class... Args> | |
decltype(auto) operator()(Args&&... args) const { | |
return f(std::ref(*this), std::forward<Args>(args)...); | |
} | |
}; | |
template < class F > | |
Fixed(F) -> Fixed<F>; |
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
Fixed fib17 = { | |
[](auto f, int n) -> int | |
{ | |
switch ( n ) { | |
case 0: return 0; | |
case 1: return 1; | |
default: return f( n - 2 ) + f( n - 1 ); | |
} | |
} | |
}; |
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
auto fib17 = Fixed | |
{ | |
[](auto f, int n) -> int | |
{ | |
switch ( n ) { | |
case 0: return 0; | |
case 1: return 1; | |
default: return f( n - 2 ) + f( n - 1 ); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment