[Issue 1961] Allow "scoped const" contracts

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 8 07:42:31 PDT 2008


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





------- Comment #7 from brunodomedeiros+bugz at gmail.com  2008-04-08 09:42 -------
Andrei & co., please don't discuss topics in the bugzilla, especially if they
are not related to the bug. That's what the NG is for, no?

As for this issue, isn't there a similar problem with member functions and the
this parameter? I.e., suppose you want to write a getter: 

  class Foo { 
    Bar bar;
    Bar getBar() {
      return bar;
    }
  }

But then the return value should have the same constness of the this parameter,
that is, when invoked with a const this, the return value should be const, but
when invoked with a mutable this, the return value should be mutable (and
similarly for invariant). It's the same concept as your inout but applied to
the this parameter. However if the getter is defined as in the code above, it
will only work for mutable this. 

How is this problem solved currently in D? I had the impression there was a way
to do it, but I can't remember it, and I couldn't it find in the documentation
either. Or am I mistaken, and there is no way to do it in D (without creating 3
distinct functions)? 


-- 



More information about the Digitalmars-d-bugs mailing list