functional.hpp 560 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef MIGRAPH_GUARD_RTGLIB_FUNCTIONAL_HPP
#define MIGRAPH_GUARD_RTGLIB_FUNCTIONAL_HPP

#include <utility>

namespace migraph {

namespace detail {

template<class R, class F>
struct fix_f
{
    F f;

    template<class... Ts>
    R operator()(Ts&&... xs) const
    {
        return f(*this, std::forward<Ts>(xs)...);
    }
};

} // namespace detail

/// Implements a fix-point combinator
template<class R, class F>
detail::fix_f<R, F> fix(F f)
{
    return {f};
}

template<class F>
auto fix(F f)
{
    return fix<void>(f);
}

} // namespace migraph

#endif