Non-Purity of Algebraic opEquals

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 18 07:20:20 PDT 2015


On 9/18/15 9:53 AM, Nordlöw wrote:
> On Friday, 18 September 2015 at 13:22:14 UTC, Nordlöw wrote:
>> Ideas anyone?
>
> I tried tagging up `VariantN` with pure until I got to
>
>      @property inout(T)* peek(T)() inout pure
>      {
>          static if (!is(T == void))
>              static assert(allowed!(T), "Cannot store a " ~ T.stringof
>                      ~ " in a " ~ VariantN.stringof);
>          if (type != typeid(T))
>              return null;
>          static if (T.sizeof <= size)
>              return cast(inout T*)&store;
>          else
>              return *cast(inout T**)&store;
>      }
>
> which then errors as
>
> variant.d(701,13): Error: pure function
> 'std.variant.VariantN!32LU.VariantN.peek!void.peek' cannot call impure
> function 'object.opEquals'
>
> for the line
>
>      if (type != typeid(T))
>
> Why is `object.opEquals` not pure?

What about type !is typeid(T)?

This should solve most cases.

-Steve


More information about the Digitalmars-d mailing list