std.v2020.algorithm etc[ WAS: Is run.d going to be expand for runtime and the phobos library?]

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Jun 22 02:58:16 UTC 2020


On 6/21/20 6:06 PM, Timon Gehr wrote:
> On 20.06.20 16:51, Andrei Alexandrescu wrote:
>>
>> Input ranges should have only one API:
>>
>> bool fetchNext(T& target);
>>
>> Fill the user-provided target with the next element and return true. 
>> At the end of the range, return false and leave the target alone.
> 
> What if the caller does not know how to construct a T?
> 
> Nullable!T fetchNext();
> 
> (I get that D's support for algebraic data types is subpar, but maybe 
> that is something to look into.)

That also creates a copy for each element, which may be disadvantageous 
for certain range types. (Also does not give access to references to the 
original elements, for you can't say Nullable!(ref T).)

Making an API that is simple and works with in-memory elements as well 
as values synthesized on the fly is quite a challenge.


More information about the Digitalmars-d mailing list