Created
June 10, 2018 06:32
-
-
Save loliGothicK/5aef669c7613425438b32abc9a1d6ad7 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<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