www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - .empty and .length Amend language manual?

reply "dcoder" <dcoder nowhere.com> writes:
I'm using the language reference on dlang.org (which is awesome), 
anyways, I can't find a description of .empty in the array 
section. Should it be there?  I don't see it in the property 
section either.

Could someone more expert than me, add it in somewhere?  Thanks.

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.
Apr 18 2012
next sibling parent "Tobias Pankrath" <tobias pankrath.net> writes:
On Wednesday, 18 April 2012 at 14:35:07 UTC, dcoder wrote:
 I'm using the language reference on dlang.org (which is 
 awesome), anyways, I can't find a description of .empty in the 
 array section. Should it be there?  I don't see it in the 
 property section either.

 Could someone more expert than me, add it in somewhere?  Thanks.

 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.

It's a function from std.array called via UFCS.
Apr 18 2012
prev sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
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
Apr 18 2012