Blog Post: Beating std::visit Without Really Trying

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Oct 6 00:52:38 UTC 2019


On 10/5/19 7:58 AM, Seb wrote:
> On Saturday, 5 October 2019 at 06:40:35 UTC, Arun Chandrasekaran wrote:
>> On Saturday, 5 October 2019 at 02:59:58 UTC, Paul Backus wrote:
>>> I was curious how C++17's std::variant compared to the options we 
>>> have in D, like Algebraic and SumType, so I did a simple comparison 
>>> of the generated assembly for each of them. You can read about it at 
>>> the link below. And as you can probably guess from the title, D comes 
>>> out ahead, in the end.
>>>
>>> https://pbackus.github.io/blog/beating-stdvisit-without-really-trying.html 
>>>
>>>
>>> This is my first attempt at sharing something like this, so any 
>>> comment or feedback is very much appreciated!
>>
>> Good one. Any plans to push SumType as a replacement of Phobo's 
>> Algebraic?
> 
> Phobos is essentially dead/frozen (feature-wise). Though if someone ever 
> manages to get v2 of the ground, SumType would be the obvious choice.

I think we'd do good to choose words with care. An extraordinary 
assertion, however odd and unjustified, may go by chance unchallenged 
and if repeated enough soon starts passing as the accepted truth. This 
is very damaging, regardless of how well it was intended initially, 
goodwill I have no doubt about. To set the record straight: Phobos is 
not dead and is not frozen feature-wise. It is and has always been open 
to adding new functionality, and of course to improve implementation of 
existing functionality.

Variant's design and implementation are very, very, very old. We're 
talking 15 years. It is literally the first generic design I've ever 
done in D, and at the time getting it (or anything nontrivial) to work 
was a large challenge. At that time only the most basic examples worked 
for any template-related feature. The code also predates most of the 
CTFE niceties we now take for granted, static foreach included. Not to 
mention, I'd be the first to say I engineered the thing poorly. A 
radical simplification is definitely possible and desirable.

> Anyhow, currently we would have to name it differently (e.g. dts - 
> https://github.com/wilzbach/dts). Maybe the upcoming SAoC project will 
> change this and allow multiple versions of a library to co-exist in a 
> binary.

Adding it as a new facility is a possibility, but only if the challenges 
of keeping the existing interface are too large.


More information about the Digitalmars-d-announce mailing list