recursive template types
<p>I want to make following code snippet to work</p>

<pre><code>typedef boost::function&lt;result_type ()&gt; functor_type;
typedef boost::variant&lt;int, functor_type&gt; result_type;
</code></pre>

<p>two types depend on each other, how to break the circular dependencies?</p>

<hr>

<p>The Motivation</p>

<p>Basicly, I want to implement tail call in c++, like this</p>

<pre><code>template&lt;typename ResultT&gt;
struct TailCall
{
    typedef ResultT result_type;
    typedef boost::function&lt;ret_type ()&gt; continuation_type;
    typedef boost::variant&lt;result_type, continuation_type&gt; ret_type;

    TailCall(const continuation_type&amp; init) : next(init) {}

    result_type operator()()
    {
         while (true) {
            ret_type r = next();
            result_type *result = boost::get&lt;result_type&gt;(&amp;r);
            if (result)
                return *result;
            else
                next = boost::get&lt;continuation_type&gt;(r);
         }
    }

private:
    continuation_type next;
};

TailCall&lt;int&gt;::ret_type fibonacci_impl(int term, int val, int prev)
{
    if (term == 0) return prev;
    if (term == 1) return val;
    return boost::bind(fibonacci_impl, term-1, val+prev, val);
}

int fibonacci(int index)
{
    TailCall&lt;int&gt; fib(boost::bind(fibonacci_impl, index, 1, 0));
    return fib();
}
</code></pre>
