Proposal to add 'Elements of Programming' Concepts to std.traits
Philippe Sigaud
philippe.sigaud at gmail.com
Sat Jun 16 23:38:41 PDT 2012
On Sat, Jun 16, 2012 at 9:22 PM, bearophile <bearophileHUGS at lycos.com> wrote:
> I see. is that semantically different from this (beside being shorter)?
>
> struct NoZero {
> int value;
> this(int x) { value = x; }
> alias value this;
> invariant() { assert(value != 0); }
> }
> void main() {
> auto a = NoZero(5);
> auto b = NoZero(0);
> }
The invariant isn't invoked through alias this, it seems:
void main() {
auto a = NoZero(5);
a = 0; // compiles and runs happily
}
More information about the Digitalmars-d
mailing list