Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

c++ generic y-combinator

Name: Anonymous 2012-06-15 20:15

Sup /prog/,
I'm having what I think are template problems with my C++ Y-combinator:


template <typename Result, typename... Args>
std::function<Result(Args...)>
Y
(std::function <Result(std::function <Result(Args...)>, Args...)> f)
{
    return
    (
        [&](Args... args) -> Result
        {
            return f(Y<Result, Args...>(f), args...);
        }

    );
}


On the line where I call the function returned by the combinator, I get this error:
no matching function for call to ‘Y(main()::<lambda(std::function<int(int)>, int)>)’
It happens even if I explicitly add the template parameters when Y is called. I can't figure out what is wrong because when I use the following version on a function that takes and returns a single int, it works perfectly:


std::function<int(int)>
Y
(std::function <int(std::function <int(int)>, int)> f)
{
    return
    (
        [&](int args) -> int
        {
            return f(Y(f), args);
        }

    );
}

Name: Anonymous 2012-06-16 0:08

why do we even need y-combinators

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List