How do you make a copy TO and object when you're INSIDE of it?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 23 19:31:43 PDT 2015


On Friday, July 24, 2015 01:30:55 Enjoys Math via Digitalmars-d-learn wrote:
> Here's my code:
>
> module grammar;
>
> class Grammar(T : ulong) {
>      this(const T[] str) {
>          auto grammar = str in grammarCache;
>
>          if (grammar) {
>              this = grammar.dup;
>          } else {
>              this = approximateSmallestGrammar(str);
>              grammarCache[str] = this.dup;
>          }
>      }
>
>      static Grammar approximateSmallestGrammar(const T[] str) {
>          return new Grammar();
>      }
>
>      @property Grammar dup() {
>
>      }
>
> private:
>      this() {}
>      static Grammar[T[]] grammarCache;
> };
>
>
> Compiler says 'this' is not an lvalue.  How would I accomplish
> what I want?

Assign to the members individually rather than the whole object at once.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list