isRandomAccessRange!(const(size_t[])) is false ... ?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Sep 12 15:16:50 PDT 2013


On Thu, Sep 12, 2013 at 03:12:48PM -0700, Ali Çehreli wrote:
> On 09/12/2013 02:53 PM, Joseph Rushton Wakeling wrote:
> >import std.range;
> >
> >void main()
> >{
> >     assert(isRandomAccessRange!(const(size_t[])));
> >}
> >
> >.... results in an assertion error.  This is a bug, no ... ?
> 
> That one is fine. You probably want a slice of const(size_t):
> 
> import std.range;
> 
> void main()
> {
>     assert(!isRandomAccessRange!(const(size_t[])));
>     assert( isRandomAccessRange!(const(size_t)[])); // <--
> }
[...]

Explanation:

const(size_t)[] means the elements of the array can't be modified, but
the array itself can (necessary to implement popFront, popBack, etc.).

const(size_t[]) means the array itself can't be modified, so popFront,
popBack are invalid. So it cannot be a range.


T

-- 
Food and laptops don't mix.


More information about the Digitalmars-d-learn mailing list