foreach, tupleof

Jacob Carlborg doob at me.com
Sun Mar 7 10:23:19 PST 2010


On 3/7/10 19:11, Ellery Newcomer wrote:
> Hello.
>
> In D1, this code fails:
>
> void foo(S)(ref S s){
> foreach(ref k; s.tupleof){
> k = 1;
> }
> }
>
> struct K{
> int g;
> }
>
> void main(){
> K k;
> foo(k);
> assert(k.g == 1);
> }
>
>
> test.d(5): Error: no storage class for value k
>
> (referring to 'k = 1;')
>
> Is this an expected error, and is there a good way to get the semantics
> to actually work?

It's a bug: http://d.puremagic.com/issues/show_bug.cgi?id=2411
You can use the following code as a workaround:

foreach (i, dummy ; s.tupleof)
	s.tupleof[i] = 1;


More information about the Digitalmars-d-learn mailing list