Skip to content

Instantly share code, notes, and snippets.

@loliGothicK
Last active April 27, 2018 19:15
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/4e9e35b716a9465032567a83887bfd21 to your computer and use it in GitHub Desktop.
Save loliGothicK/4e9e35b716a9465032567a83887bfd21 to your computer and use it in GitHub Desktop.
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>;
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 );
}
}
};
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