https://d.puremagic.com/issues/show_bug.cgi?id=12530



--- Comment #2 from monarchdo...@gmail.com 2014-04-06 13:02:13 PDT ---
(In reply to comment #1)
> Please show one or more use cases.

I've had need of this, for example, to transform the types of variadic
arguments, before passing them to another function. "reduce" or
"uninitializedArray" come to mind:

//----
void main()
{
    uninitialized!(int[][])(1, 2);
}

alias ToSizeT(T) = size_t;
enum  IsSizeT(T) = is(S == size_t);

auto uninitialized(T, Args...)(Args args)
{
    //transform the "int" inference to "size_t"
    alias SizeTArgs = staticMap!(ToSizeT, Args);

    //Call with the same arguments, but cast to size_t...
    //if the cast is implicitly safe
    return impl!T(SizeTArgs(args));
}

auto impl(T, Args...)(Args args) //Avoid bloat by requesting size_t args.
{
    static assert(allSatisfy!(IsSizeT, Args));
}
//----

The same design can be used to transform/forward args, say to unqualify all of
them at once:
//----
void myFun(Args(Args args))
{
    alias UArgs = staticMap!(Unqual, Args);
    static if (!is(UArgs == ARgs))
        myFun(UArgs(args));
    else
    {
        //actual implementation here
    }
}

Or, in the case of reduce, to build the different seeds from front:
auto result = tuple(SeedTypes(r.front));

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to