Skip to content

Instantly share code, notes, and snippets.

@loliGothicK
Created June 10, 2018 06:36
Show Gist options
  • Save loliGothicK/f8f7d5a51bb9d4b265d45b46cf51e2e8 to your computer and use it in GitHub Desktop.
Save loliGothicK/f8f7d5a51bb9d4b265d45b46cf51e2e8 to your computer and use it in GitHub Desktop.
template<typename F>
class FixPoint
{
public:
explicit constexpr FixPoint(F&& f) noexcept
: m_f(std::forward<F>(f))
{}
template<typename... Args>
constexpr decltype(auto)
operator()(Args&&... args) const
{
return m_f(*this, std::forward<Args>(args)...);
}
private:
const F m_f;
}; // 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