On 2013-11-21 08:38, Jacob Carlborg wrote:
On 2013-11-21 01:16, Simen Kjærås wrote:

The result of re-validating is performance loss. The result of missed
validation is a bug. Also, in just a few lines, you can make a version
that will *not* decay to the original type:

   struct Validated(alias fn, T) {
       private T _value;
       @property inout
       T value() {
           return _value;
       }
   }

   // validated() is identical to before.

Sure, using it is a bit more verbose than using the unadorned type,
which is why I chose to make the original version automatically decay.
This is a judgment where sensible people may disagree, even with
themselves on a case-by-case basis.

It's still accessible via "value".


Indeed it is. If we want to make it perfectly impossible to get at the contents, so as to hinder all possible use of the data, I suggest this solution:

struct Validated {}

Validated validate() {
    return Validated.init;
}

--
  Simen

Reply via email to