Ranges and/versus iterators

grauzone none at example.net
Tue Mar 23 14:21:21 PDT 2010


Andrei Alexandrescu wrote:
> On 03/23/2010 04:06 PM, grauzone wrote:
>> Steven Schveighoffer wrote:
>>> A while back, you identified one of the best interfaces for input 
>>> ranges:
>>>
>>> E* getNext();
>>>
>>> Which allows for null returns when no data is left. The drawback is
>>> that E must be either referenced or allocated on the heap (providing
>>> storage to the function is an option). But the killer issue was that
>>> safeD would not allow it. However, in recent times, you have hinted
>>
>>
>> Nullable!(E) getNext(); ?
> 
> And if returning a reference...?

Extend auto ref to template parameters:

struct Nullable(auto ref T) { ... }

T would be actually a reference type if and only if you could return a 
reference to the variable the template parameter was inferred from from 
a SafeD function. Basically, the compiler would know that references to 
T can be passed around freely. (SafeD allows ref returns under 
circumstances.)

Not a solution I would prefer, but in the spirit of the design of D2 and 
SafeD in general.

> Andrei



More information about the Digitalmars-d mailing list