[OT] Re: @gc attribute for bypassign @nogc

jdfgjdf via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 28 11:06:50 PDT 2016


On Thursday, 28 July 2016 at 17:54:20 UTC, jdfgjdf wrote:
> On Sunday, 24 July 2016 at 22:13:02 UTC, bitwise wrote:
>> ...
>
> I like the  typo in the title. Let's make a game:
>
> "write the `bypassign` function, its ddoc, and its unittests"
>
> :)

Entry one:

/**
  * Bypassign is a struct wrapper that bypasses the original 
type's `opAssign()`,
  * thus any assignation to the wrapped type is a noop.
  */
struct Bypassign(T)
if (is(T == struct))
{
     private T _bypassigned;
     alias _bypassigned this;
     void opAssign(T)(auto ref T t)
     {/*bypassignation*/}
}
///
unittest
{
     static struct Foo
     {
         int i;
         alias i this;
     }
     Bypassign!Foo bpaFoo;
     bpaFoo = 1;
     assert(bpaFoo == 0);
}




More information about the Digitalmars-d mailing list