Out of bound problem
Sergey Gromov
snake.scaly at gmail.com
Sat Feb 16 19:13:28 PST 2008
bearophile <bearophileHUGS at lycos.com> wrote:
> TA[] foo(TA, TB)(TA[] a, TB b) {
> TA[] result;
>
> static if (IsArray!(TB)) {
> if (b.length == 0) {
> result = a;
> } else if (b.length == 1) {
> result = foo(a, b[0]);
> }
> }
>
> return result;
> }
It seems to replace the line
result = foo(a, b[0]);
with
result = foo("test", ""[0]);
and then complain that the constant expression ""[0] is wrong. It's
about distinguishing between static and dynamic arrays which I don't
know how to do.
In your case, adding static if(b.sizeof) should do the trick: only empty
static arrays have zero size.
--
SnakE
More information about the Digitalmars-d-learn
mailing list