foreach reference to struct variable

Unknown W. Brackets unknown at simplemachines.org
Thu Feb 7 21:40:58 PST 2008


You can use the actual & operator...

	int a = 5;
	auto b = &a;

	writefln("a: %s, b: %s", a, *b);

And there's also this, but it's not exactly the same thing (it literally 
is just an aliased variable name):

	int a = 5;
	alias a b;

	writefln("a: %s, b: %s", a, b);

-[Unknown]


Prashant V wrote:
> Denton Cockburn Wrote:
>> use ref while indexing:
>>
>> foreach (ref s; structs)
>>    // do something
> 
> Ah that works great! Thanks. Is there anything similar for variables. Eg can I go
> 
> int test = 5;
> ref auto test2 = test;
> test++;
> 
> and have the change reflected in test?



More information about the Digitalmars-d mailing list