Fixed point combinator in C++1x This has been tested and compiled under Visual Studio 2010. Are there any serious problems with this implementation?

PS. This implementation is fully lambda expression based. If I can make fixpoint::fix a real member function it will be simpler than this.

//As decltype(variable)::member_name is invalid currently, 
//the following template is a workaround.
//Usage: t2t&lt;decltype(variable)&gt;::t::member_name
template&lt;typename T&gt;
struct t2t
{
    typedef T t;
};

template&lt;typename R, typename V&gt;
struct fixpoint
{
    typedef std::function&lt;R (V)&gt; func_t;
    typedef std::function&lt;func_t (func_t)&gt; tfunc_t;
    typedef std::function&lt;func_t (tfunc_t)&gt; yfunc_t;

    class loopfunc_t {
    public:
        func_t operator()(loopfunc_t v)const {
            return func(v);
        }
        template&lt;typename L&gt;
        loopfunc_t(const L &amp;l):func(l){}
        typedef V Parameter_t;
    private:
        std::function&lt;func_t (loopfunc_t)&gt; func;
    };
    static yfunc_t fix;
};
template&lt;typename R, typename V&gt;
typename fixpoint&lt;R, V&gt;::yfunc_t fixpoint&lt;R, V&gt;::fix = 
[](fixpoint&lt;R, V&gt;::tfunc_t f) -&gt; fixpoint&lt;R, V&gt;::func_t {
    fixpoint&lt;R, V&gt;::loopfunc_t l = [f](fixpoint&lt;R, V&gt;::loopfunc_t x) -&gt;
        fixpoint&lt;R, V&gt;::func_t{
            //f cannot be captured since it is not a local variable
            //of this scope. We need a new reference to it.
            auto &amp;ff = f;
            //We need struct t2t because template parameter
            //V is not accessable in this level.
            return [ff, x](t2t&lt;decltype(x)&gt;::t::Parameter_t v){
                return ff(x(x))(v); 
            };
        }; 
        return l(l);
    };

int _tmain(int argc, _TCHAR* argv[])
{
    int v = 0;
    std::function&lt;int (int)&gt; fac = 
    fixpoint&lt;int, int&gt;::fix([](std::function&lt;int (int)&gt; f)
        -&gt; std::function&lt;int (int)&gt;{
        return [f](int i) -&gt; int{
            if(i==0) return 1;
            else return i * f(i-1);
        };
    });

    int i = fac(10);
    std::cout &lt;&lt; i; //3628800
    return 0;
}
I hav tried the same thing in G++ (version 4.5 from Ubuntu 11.04 original), and the result is quite impressing me. We now do have a lot more features to generise the solution. 


we can now support any number of parameters without modifying the code.
the t2t class is no longer needed as G++ lambda supports accessing all identifiers in scope, including global things. 


I also tried write a free template function to access the internal function. And the result looks good. I just wanted to say: it is elegant!

#include &lt;iostream&gt;
#include &lt;functional&gt;

template&lt;typename R, typename... V&gt;
struct fixpoint
{
    typedef std::function&lt;R (V...)&gt; func_t;
    typedef std::function&lt;func_t (func_t)&gt; tfunc_t;
    typedef std::function&lt;func_t (tfunc_t)&gt; yfunc_t;

    class loopfunc_t {
    public:
        func_t operator()(loopfunc_t v)const {
            return func(v);
        }
        template&lt;typename L&gt;
        loopfunc_t(const L &amp;l):func(l){}
        loopfunc_t(){}
    private:
        std::function&lt;func_t (loopfunc_t)&gt; func;
    };
    static func_t Fix(tfunc_t f){
        return [](loopfunc_t x){ return x(x); }
        ([f](loopfunc_t x){ return [f, x](V... v){ return f(x(x))(v...); }; });
    }
};
template&lt;typename T&gt;
struct getfixpoint
{
    typedef typename getfixpoint&lt;decltype(&amp;T::operator())&gt;::fp fp;
};
template&lt;typename R, typename T, typename... V&gt;
struct getfixpoint&lt;std::function&lt;R (V...)&gt; (T::*)(std::function&lt;R (V...)&gt;)&gt;
{
    typedef fixpoint&lt;R, V...&gt; fp;
};
template&lt;typename R, typename T, typename... V&gt;
struct getfixpoint&lt;std::function&lt;R (V...)&gt; (T::*)(std::function&lt;R (V...)&gt;)const&gt;
{
    typedef fixpoint&lt;R, V...&gt; fp;
};
template&lt;typename R, typename... V&gt;
struct getfixpoint&lt;std::function&lt;R (V...)&gt; (*)(std::function&lt;R (V...)&gt;)&gt;
{
    typedef fixpoint&lt;R, V...&gt; fp;
};

template&lt;typename T&gt;
auto getFix(T f) -&gt; typename getfixpoint&lt;T&gt;::fp::func_t {
    return getfixpoint&lt;T&gt;::fp::Fix(f);
};

int main(int argc, char* argv[])
{
    auto fac = getFix([](std::function&lt;int (int)&gt; f) -&gt; std::function&lt;int (int)&gt;{
        return [f](int n)-&gt;int { if(n==0) return 1; else return n * f(n-1); };
    });
    std::cout&lt;&lt;fac(10)&lt;&lt;std::endl; //3628800
    return 0;
}