www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - foreach doesn't seem to know about invariant

reply "Janice Caron" <caron800 googlemail.com> writes:
foreach doesn't seem to know about invariant. Watch...

    import std.stdio;

    void main()
    {
        string s = "hello";
        foreach(ref c;s) { c = '*'; }
        writefln(s);
    }

Prints
*****
Nov 22 2007
next sibling parent reply "Stewart Gordon" <smjg_1998 yahoo.com> writes:
"Janice Caron" <caron800 googlemail.com> wrote in message 
news:mailman.113.1195747061.2338.digitalmars-d puremagic.com...
 foreach doesn't seem to know about invariant. Watch...

<snip> Known bug. http://d.puremagic.com/issues/show_bug.cgi?id=1322 Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit.
Nov 22 2007
parent Ary Borenszweig <ary esperanto.org.ar> writes:
Stewart Gordon wrote:
 "Janice Caron" <caron800 googlemail.com> wrote in message 
 news:mailman.113.1195747061.2338.digitalmars-d puremagic.com...
 foreach doesn't seem to know about invariant. Watch...

<snip> Known bug. http://d.puremagic.com/issues/show_bug.cgi?id=1322 Stewart.

And also: http://d.puremagic.com/issues/show_bug.cgi?id=1615
Nov 22 2007
prev sibling parent "Janice Caron" <caron800 googlemail.com> writes:
It'll be interesting to see how we're supposed to overload that with
opApply, taking const into account, in the next version of const. Do
we have to write the function twice? (Four times if you also have to
write Value-only versions).

const int opApply(int delegate(Key key, Value value) dg)
{
    /* whatever */
}

int opApply(int delegate(Key key, ref Value value) dg)
{
    /* whatever */
}

I don't think you can say "ref const(Value) value".
Nov 22 2007