[phobos] Error: functions cannot return a tuple

Sean Kelly sean at invisibleduck.org
Fri Jun 4 15:28:59 PDT 2010


This is a fun one.  I don't suppose someone can suggest a workaround?  If an argument is added to the call to foo() in main (so it really does return a Tuple) the code compiles without incident.  I ran into this while making sure all the code samples in TDPL ch.13 work.


    import std.typecons;

    template fooRet(T...)
    {
        static if( T.length == 1 )
            alias T fooRet;
        else
            alias Tuple!(T) fooRet;
    }

    fooRet!(T) foo(T...)(T vals)
    {
        Tuple!(T) ret;
        static if( T.length == 1 )
            return ret.field[0];
        else
            return ret;
    }

    void main()
    {
        auto x = foo(1)();
    }


More information about the phobos mailing list