On Thursday, 7 May 2020 at 10:41:01 UTC, Simen Kjærås wrote:
On Thursday, 7 May 2020 at 09:22:28 UTC, learner wrote:
Good morning,

Is there a reason why std.variant.visit is not inferring pure?

```
void test() pure {
    Algebraic!(int, string) alg;
    visit!( (string) => 0, (int) => 0)(alg);
}

Error: pure function test cannot call impure function test.visit!(VariantN!(16LU, int, string)).visit
```

std.variant.Algebraic is essentially a std.variant.Variant in different clothes. Variant is very flexible, and this comes at a cost (and isn't used in Algebraic, meaning you pay for things you don't use). Like Dukc said, you might be better off with Taggedalgebraic or SumType (https://code.dlang.org/packages/sumtype).


Variant uses runtime type information to hold *any* type. Since Algebraic specifically only holds a few types, all the framework that's in place for Variant is wasted on Algebraic, and makes it less useful and less performant.

--
  Simen

Thank you Simon and Dukc,

I've find this: https://issues.dlang.org/show_bug.cgi?id=16662

So, it seems that Phobos isn't in a good shape ... what a pity!

Reply via email to