Const ref and rvalues again...

Era Scarecrow rtcvb32 at yahoo.com
Tue Nov 13 03:44:09 PST 2012


On Tuesday, 13 November 2012 at 10:09:27 UTC, luka8088 wrote:
> Can you point out any existing public code that would be broken?

  Off hand, no.. I'm not that familiar with a lot of the code or 
the in depth details of phoboes; However suddenly reversing what 
is mutable and what is const is bound to break a lot of things 
even unintentionally.

  Hmmm.. Does remind me of a bit of my code sometimes... Something 
went like...

  class S {
    void func(S s) {
      if (!s)
        s = new S(); //create one if not passed in.

      //process using S and s (be it new or passed in)
    }
  }

  That would certainly cause a problem.. In my own code example it 
may empty the pointer/reference if certain requirements were met, 
and then use if the class reference was set or null for later 
logic (even if the object referenced to wasn't changed...). 
Course being passed something like a string... (seems the most 
likely place you'd find it), in which case using .dup on the 
input string right back into the variable would be completely 
understandable. ie:

string someStringTransformationWithCOW(string x) {
   //if COW'd then
   x = x.dup;

   //...
   return x;
}

  Course having the input as char[] rather than string makes more 
sense for on the fly changes before returning it...


More information about the Digitalmars-d mailing list