[Issue 8687] Variadic templates do not work properly with default arguments

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jan 7 00:18:57 UTC 2018


https://issues.dlang.org/show_bug.cgi?id=8687

Martin Nowak <code at dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code at dawg.eu

--- Comment #5 from Martin Nowak <code at dawg.eu> ---
While working on limited lifetimes (@safe RC/Uniq) I ran into another use-case
where a default argument is needed.

// use implicit allocator argument
RC!T rc(T, Alloc, Args...)(Args args, return scope Alloc = Mallocator.instance)
if (!Args.length || !isAllocator!(Args[$-1]));

Adding the default argument inside of the function body (instead of in the
signature), wouldn't be able to convey the lifetime information from the
argument to the return value, hence it has to be a default argument which is
evaluated on the call-site.

An algorithm for IFTI would be fairly simple, greedily match the variadic
parameter to all remaining arguments, then add in all the default arguments. 

The above case would have another overload for non-default allocators.

// last argument is explicit allocator
RC!T rc(T, Args...)(return scope Args args) if (Args.length &&
isAllocator!(Args[$-1]));

Indeed this shouldn't be too complex to support in the compiler.

--


More information about the Digitalmars-d-bugs mailing list