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);
}