On Wednesday, 28 December 2011 at 19:48:28 UTC, Adam D. Ruppe wrote:
On Wednesday, 28 December 2011 at 19:30:04 UTC, Andrei Alexandrescu wrote:
Implementation would entail a change in the compiler.

I don't think I agree. Wouldn't something like this work?

===

struct string {
      immutable(char)[] rep;
      alias rep this;
      auto opAssign(immutable(char)[] rhs) {
              rep = rhs;
              return this;
      }

      this(immutable(char)[] rhs) {
              rep = rhs;
      }
      // disable these here so it isn't passed on to .rep
      @disable void opSlice(){  assert(0);  };
      @disable size_t length() {  assert(0);  };
}

===

I did some quick tests and the basics seemed ok:

/* paste impl from above */

import std.string : replace;

void main() {
      string a = "test"; // works

      a = a.replace("test", "mang"); // works
      // a = a[0..1]; // correctly fails to compile
      assert(0, a); // works
}

My thinking exactly. Of course we can't put "@disable" right away and should start with "@deprecated" to allow for a proper migration period. I'd also like a transition of the string related functions to this type. the previous ones can remain as simple wrappers/aliases/whatever for backwards compatibility.

Reply via email to