std.variant Is Everything Cool About D

Meta jared771 at gmail.com
Wed Apr 4 03:29:14 UTC 2018


On Wednesday, 4 April 2018 at 03:09:22 UTC, helxi wrote:
> On Thursday, 29 March 2018 at 14:10:39 UTC, Mike Parker wrote:
>> Jared Hanson (a.k.a Meta and MetaLang around these parts) was 
>> inspired by an article titled "std::visit is everything wrong 
>> with modern C++" to contrast it with D's std.variant.visit. 
>> The result is this well-written post for the D Blog.
>>
>> The blog:
>> https://dlang.org/blog/2018/03/29/std-variant-is-everything-cool-about-d/
>>
>> Reddit:
>> https://www.reddit.com/r/programming/comments/881hmi/stdvariant_is_everything_cool_about_d/
>
> What is the difference between 
> https://dlang.org/phobos/std_typecons.html#Nullable and 
> Algebraic!(T, typeof(null))?

Nullable is specifically specialized to this particular use-case 
and only has to store a boolean in addition the wrapped data (and 
there is a template "overload" that allows you to specify a 
specific value for the `null` state, which removes even that 
boolean). Also, with Nullable your data is guaranteed to not be 
boxed, whereas it's a possibility with Variant/Algebraic if the 
types you're working with are large enough.


More information about the Digitalmars-d-announce mailing list