On Monday, 31 March 2014 at 10:09:06 UTC, Artur Skawina wrote:
No. This will bite you once you decide to overload Impl's ops, such as indexing and slicing.

I agree with you that this is a problem that can bite you, but there's a fairly easy solution: you shouldn't overload Impl's ops, nor should it have constructors, postblits, or destructors since they won't run when you expect them to either. Putting them on the outer struct works right and opens the door to new things like refcounting too.

But yeah, you're right that it would still compile if you did it wrong and that's potentially ugly.

   struct RefType {
      struct Impl {
           // put all the stuff in here

           @disable this(this);
      }
      Impl* impl;
      ref Impl _get() @property { return *impl; }
      alias _get this;

      // add ctors and stuff that new the impl
   }


not bad to my eyes,

Reply via email to