www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2411] New: Reference Tuple Foreach

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2411

           Summary: Reference Tuple Foreach
           Product: D
           Version: 2.019
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: dsimcha yahoo.com


Sometimes, when iterating over a tuple representation of a class or struct, I
want to modify the class/struct contents.  Ex:

struct S {
    uint foo = 1;
}

void main() {
    S s;
    foreach(element; s.tupleof)
        element = 2;
    writeln(s.foo); //Still prints 1
}

It would be nice if I could do something like:

foreach(ref element; s.tupleof)

and this would modify s.foo.


-- 
Oct 09 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2411


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sean invisibleduck.org





---
*** Issue 3045 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 02 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2411


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



Bug 3835 is a partial duplicate of this (one case seems different).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 07 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2411


Trass3r <mrmocool gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mrmocool gmx.de



This is a workaround:

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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 20 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2411


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch



https://github.com/D-Programming-Language/dmd/pull/596

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2411




My patch requires explicit 'ref'.

void main() {
    S s;
//  foreach(    element; s.tupleof)  // doesn't work
    foreach(ref element; s.tupleof)  // OK
        element = 2;
    assert(s.foo == 2);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 01 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2411





 My patch requires explicit 'ref'.
 
 void main() {
     S s;
 //  foreach(    element; s.tupleof)  // doesn't work
     foreach(ref element; s.tupleof)  // OK
         element = 2;
     assert(s.foo == 2);
 My patch requires explicit 'ref'.
 
 void main() {
     S s;
 //  foreach(    element; s.tupleof)  // doesn't work
     foreach(ref element; s.tupleof)  // OK
         element = 2;
     assert(s.foo == 2);
 }
It seems to me like the only logical way to do this is to require explicit ref. The semantics should be the same as foreach over ranges. Nice work. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 01 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2411


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



12:25:30 PST ---
https://github.com/D-Programming-Language/dmd/commit/d3294a136cf6355442dc4e897e46334655f92f15

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 10 2012