RFC: std.sumtype (adding sumtype to Phobos)

bachmeier no at spam.net
Wed Nov 25 17:53:41 UTC 2020


On Wednesday, 25 November 2020 at 16:12:14 UTC, Paul Backus wrote:
> On Wednesday, 25 November 2020 at 15:50:47 UTC, bachmeier wrote:
>>
>> The "Basic Usage" examples show functions preceded by "pure 
>> @safe @nogc nothrow". Is that required? If so, do we want to 
>> go down the path of adding that kind of verbosity/complexity 
>> to Phobos libraries? That would be a substantial change from 
>> what we have now. It would definitely make the language less 
>> appealing (particularly with two starting with @ and two not).
>
> No, the attributes are not required. They're just there to show 
> that SumType *can* be used in @safe/pure/nothrow/@nogc code, if 
> desired. Maybe it's better to leave them off, though, if 
> they're distracting readers from the main topic of the example.

If that's the case, I agree that it's a good thing to show. You 
might consider having a clean version of toFahrenheit and then 
something like

// SumType can be used in @safe/pure/nothrow/@nogc code
pure @safe @nogc nothrow
void freeze(ref Temperature t)

Whatever you do with that, it clears up my concern and I would 
like to see this added to Phobos.


More information about the Digitalmars-d mailing list