On 7/23/18 2:39 PM, aliak wrote:
Hi,

I'm playing around with an Optional wrapper type. It stores a type T and a bool that defines whether a value is defined or not:

struct Optional(T) {
   T value;
   bool defined = false;
   this(U : T)(auto ref inout(U) value) inout {
     this.value = value;
     this.defined = true;
   }
}

Don't use inout here. The point of inout on the constructor is to *transfer* the mutability of the parameter to the struct instance. But you want to simply copy the type into the struct (an immutable(Optional!T) is quite useless, no?)

Just use U, not inout(U), and don't put inout on the constructor.

-Steve

Reply via email to