Struct y_combinator

Synopsis

#include <src/entt/core/utility.hpp>

template<class Func>
struct y_combinator

Description

Basic implementation of a y-combinator.

Template Parameters

Func - Type of a potentially recursive function.

Mentioned in

Methods

y_combinatorConstructs a y-combinator from a given function.
operator() overloadInvokes a y-combinator and therefore its underlying function.

Source

Lines 69-97 in src/entt/core/utility.hpp.

template<class Func>
struct y_combinator {
    /**
     * @brief Constructs a y-combinator from a given function.
     * @param recursive A potentially recursive function.
     */
    y_combinator(Func recursive)
        : func{std::move(recursive)} {}

    /**
     * @brief Invokes a y-combinator and therefore its underlying function.
     * @tparam Args Types of arguments to use to invoke the underlying function.
     * @param args Parameters to use to invoke the underlying function.
     * @return Return value of the underlying function, if any.
     */
    template<class... Args>
    decltype(auto) operator()(Args &&...args) const {
        return func(*this, std::forward<Args>(args)...);
    }

    /*! @copydoc operator()() */
    template<class... Args>
    decltype(auto) operator()(Args &&...args) {
        return func(*this, std::forward<Args>(args)...);
    }

private:
    Func func;
};





Add Discussion

Log in to comment