Multiple return value as requirements for safety and performance

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Tue Dec 20 12:02:47 PST 2016


On 20.12.2016 14:47, Ilya Yaroshenko wrote:
> One good thing for safety and CTFE is allow multiple return value. In
> combination with `auto ref` it is _very_ powerful:
>
> ----
> auto ref front()
> {
>   // Returns 2 values, each value is returned by reference if possible
>   return (a.front, b.front);
> }
> ----
> ...


There is already syntax for something similar to this (for the 
auto-expanding version).

auto ref seq(T...)(return auto ref T args){
     return args;
}

auto ref front(){
     return seq(a.front, b.front);
}

However, DMD will reject this at the moment.


> Mir libs will use pointers for now. This is one of reasons why `zip` is
> slow.
> The new feature also significantly extends std.range and std.algorithm
> functionality.
>
> This thread was forked from
> http://forum.dlang.org/post/acdwfbirvoxzrsfyltqd@forum.dlang.org
>
> I am not good in DIPs and hope someone is interested in this feature too

This will likely be added as soon as the comma operator has finished its 
deprecation cycle. (I might give this a shot after finally polishing the 
static foreach DIP.)


More information about the Digitalmars-d mailing list