[Issue 7543] inout opApply should work properly

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 9 16:07:22 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7543



--- Comment #10 from Steven Schveighoffer <schveiguy at yahoo.com> 2012-03-09 16:07:27 PST ---
(In reply to comment #8)

> Indeed.  The point is that there are two possible interpretations of the
> opApply signature, and the spec isn't clear on which applies:
> 
> (a) the constancy is passed through to the delegate
> (b) the delegate has an inout parameter in its own right

I think it must be (b).  Consider you don't know when the delegate was
constructed:

void foo(inout(int)* x, inout(int)* delegate(inout(int)* x) dg)
{
   inout(int)* bar(inout(int)* m) { return m;}
   auto dg2 = &bar;
   assert(typeof(dg2) == typeof(dg)); // ???

   immutable int y = 5;
   dg2(&y); // ok
   dg(&y); // must fail!
}

If the assert doesn't pass, then what is the type of dg vs. dg2?  If it passes,
then dg and dg2 are interchangeable, and you will violate const (what if x is
mutable?).  Even if the assert fails, it's going to be way *way* too confusing
to have two types that are identical in syntax be actually different types
under the hood.

We *absolutely* need a new syntax if case (a) is to be included.

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


More information about the Digitalmars-d-bugs mailing list