.empty and .length Amend language manual?

bearophile bearophileHUGS at lycos.com
Wed Apr 18 07:47:13 PDT 2012


dcoder:

> Also, is there any surprises / difference between the two:
>
> if( !arr.length)
>
> and
>
> if( arr.empty)
>
> do they produce the same thing all the time?
>
> thanks.

No surprises here, thankfully. Its implementation:
https://raw.github.com/D-Programming-Language/phobos/master/std/array.d

@property bool empty(T)(in T[] a) @safe pure nothrow
{
     return !a.length;
}


In that file I'd like one more function like this:

@property bool empty(K, V)(in V[K] a) @safe pure nothrow
{
     return !a.length;
}

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list