Truth value of an empty slice
monarch_dodra
monarchdodra at gmail.com
Wed Jan 9 05:50:12 PST 2013
On Wednesday, 9 January 2013 at 13:38:21 UTC, MrOrdinaire wrote:
> On Wednesday, 9 January 2013 at 13:29:39 UTC, bearophile wrote:
>> See also this old ER of mine:
>>
>> http://d.puremagic.com/issues/show_bug.cgi?id=4733
>>
>> Bye,
>> bearophile
>
> Thank you. This clears up the question.
Long story short: the result of "cast(bool)arr" is equivalent to
"cast(bool)(arr.ptr)"
For example:
//----
import std.array;
void main()
{
int[] a;
int[] b = [1, 2];
int[] c = b[0 .. 0];
int[] d = b[$ .. $];
assert(!a); //assert(!a.ptr);
assert(b); //assert(b.ptr);
assert(c); //assert(c.ptr);
assert(sameHead(b, c));
assert(sameTail(b, d));
}
//----
More information about the Digitalmars-d-learn
mailing list