Check whether a range is empty
Ali Çehreli
acehreli at yahoo.com
Sat Jul 14 17:20:52 UTC 2018
First, please show us code that demonstrates the issue.
On 07/14/2018 07:47 AM, vino.B wrote:
> The reason it never prints the text "Empty" is that the out of the
> "r" is just an empty array.
>
> OUTPUT:
> []
> []
If that's the output of r, then r is not empty but has two elements and
those elements are likely arrays. If they are in fact arrays, them being
empty does not change r: it still has two elements.
If you want to treat the range as empty when all its elements are empty,
then perhaps your problem needs std.algorithm.joiner. The following
program demonstrates your issue with the first assert and the fix with
the second assert:
import std.algorithm;
import std.range;
void main() {
int[][] r = [ [], [] ];
assert(!r.empty);
auto joined_r = r.joiner;
assert(joined_r.empty);
}
joiner joins elements that are ranges themselves. For example, joiner([
[1], [2] ]) is equal to [ 1, 2 ].
Ali
More information about the Digitalmars-d-learn
mailing list