Jonathan M Davis <> changed:

           What    |Removed                     |Added
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |
         Resolution|                            |INVALID

--- Comment #2 from Jonathan M Davis <> 2011-07-12 11:25:38 
PDT ---
Of course startsWith won't accept something which was an in parameter. That
would make it const. And a const range is useless. startsWith could work for
const arrays if templates were smart enough to realize that (see bug# 6148),
but they're not. They instantiate with the exact type that you give them, and a
const array can't have popFront called on it, so it's useless in a range-based

Now, if the fix for bug# 6289 gets pulled in, then it'll be possible to use
const arrays with range-based functions by slicing them

void foo(in string str)
    startsWith(str[], "a");

but as long as a slice of an array is the exact same type as the original
instead of making the slice mutable (leaving the elements at the appropriate
level of mutability of coures - immutable in the case of string), that doesn't
work. You can cast the string - startsWith(cast(string)str, "a") - and it
should work just fine, but as long str is const, it won't. So, this is not a
bug that's going to be fixed by changing anything with startsWith. It's an
inherent limitation in the language with regards to templates. Improving the
situation with slicing const/immutable arrays should help, because then you can
just slice them (as you would have to do with a static array), but until then,
a cast is your best option.

Of course, I would point out that having a string be in is of debatable value
in the first place, since the original array can't be altered anyway. All it
does is make it so that str can't be reassigned to another string inside of
foo. Granted, you may want that, but in plenty of cases, it really doesn't buy
you much.

So, this bug really isn't a bug. Fixing bug# 6289 would make slicing the string
work, which would effectively fix this issue, and if bug# 6148 were ever
implemented, then that would definitely fix it (though it's questionable
whether that's ever going to happen), but as it stands, startsWith isn't doing
anything wrong. If it worked before, it was a bug in dmd.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to