Define .empty property for hashes?

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 5 14:37:52 PST 2012


On Fri, 02 Mar 2012 16:21:00 -0500, Ali Çehreli <acehreli at yahoo.com> wrote:

> On 03/02/2012 01:08 PM, Andrej Mitrovic wrote:
>  > Is there a reason why there's no .empty property for hashes? std.array
>  > defines it for arrays, and range types must have it defined.
>
> Yes, empty is a part of the InputRange interface. Slices are InputRange  
> ranges but associative arrays are not. Unless they also provide front,  
> which would returns a tuple of key and value I guess, and popFront()  
> which would remove that key and value.
>
> But things get interesting again because implementing empty, front, and  
> popFront() on the AA interface would conflate the collection with a  
> range.

Defining .empty for hashes does not make it a range.  It could (should) be
defined.  Just don't define popFront (which has little meaning anyway).

-Steve


More information about the Digitalmars-d-learn mailing list