Blog Post: Beating std::visit Without Really Trying

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Sun Oct 6 21:49:59 UTC 2019


On Sunday, 6 October 2019 at 14:08:07 UTC, Adam D. Ruppe wrote:
> D can eliminate error paths at compile time too, e.g. static 
> assert - which can be used to create all kinds of new useful 
> errors. So I am guessing this is just a case of the code 
> needing a lil tweak or the compiler being conservative and 
> putting the code in even though it is never supposed to happen 
> (like final switch keeps an error path because you can do like 
> cast(some_enum) value_not_in_enum.... and then better to have 
> the assertion failure than UB.)

Good to hear. I confess I was a bit mystified about why it should 
be an issue for D or why compiler vs. library implementation 
should make a difference to the ability to eliminate the error 
path (I infer from your remarks that it shouldn't, in principle).

I'm not fluent in assembly so, leaving the error path aside, I 
wasn't sure how to interpret the "main path" assembly from the D 
and Rust code, and whether they were practically equivalent 
(clearly the assembly posted looked different). Can anyone offer 
any interpretation there?


More information about the Digitalmars-d-announce mailing list