DIP 1010--Static foreach--Formal Review

jmh530 via Digitalmars-d digitalmars-d at puremagic.com
Tue Jul 11 07:08:25 PDT 2017


On Tuesday, 11 July 2017 at 07:42:22 UTC, Timon Gehr wrote:
>
> Yes, this code works and does what you want. (The difference to 
> inout is that you actually get three different implementations 
> and you are able to vary the implementation based on T.)

Clearly, this has more power than inout.

I suppose what I'm wondering if it makes inout superfluous. For 
instance, we should be able to add something like
template Inout(T) { alias Inout = AliasSeq(T, const(T), 
immutable(T)); }
and use static foreach on it to replicate one of inouts most 
useful features.

The other major use of inout is something like

class Foo
{
	void bar(int t) inout
	{
	}
}

which I imagine could be replaced now with SetFunctionAttributes, 
though my method was a little ugly and I don't know if there's a 
more elegant approach with static foreach.


More information about the Digitalmars-d mailing list