Skip to content

Instantly share code, notes, and snippets.

@loliGothicK
Created June 10, 2018 06:32
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/5aef669c7613425438b32abc9a1d6ad7 to your computer and use it in GitHub Desktop.
Save loliGothicK/5aef669c7613425438b32abc9a1d6ad7 to your computer and use it in GitHub Desktop.
template<typename F>
class FixPoint : F
{
public:
explicit constexpr FixPoint(F&& f) noexcept
: F(std::forward<F>(f))
{}
template<typename... Args>
constexpr decltype(auto)
operator()(Args&&... args) const
{
return F::operator()(*this, std::forward<Args>(args)...);
}
}; // class FixPoint
int
main()
{
auto result = FixPoint{[](auto&& f, int n) -> int {
return n <= 1 ? n : (f(n - 1) + f(n - 2));
}}(10);
std::cout << result << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment