alias this + std.array.popFront

Jonathan M Davis jmdavisProg at gmx.com
Fri Mar 29 17:22:59 PDT 2013


On Friday, March 29, 2013 23:22:36 Tobias Pankrath wrote:
> On Friday, 29 March 2013 at 22:13:31 UTC, Tobias Pankrath wrote:
> > Hello,
> > 
> > the following struct is not an input range because you can't
> > call popFront on it, however I'd say you should be able to.
> > 
> > struct Wrapper {
> > 
> > int[] _data;
> > alias _data this;
> > 
> > }
> > 
> > Bug or intended behaviour?
> > 
> > Thank you!
> 
> The reason seems to be that, while is(DynamicArrayTypeOf!Wrapper
> == int[]) holds, isDynamicArray!Wrapper equals false, because
> isDynamicArray checks for !isAggregateType!Wrapper. Looks like a
> bug isDynamicArray to me.

No, it is most definitely _not_ a bug in isDynamicArray. The isX traits in 
std.traits specifically check for exact tyes and _not_ implicit conversions. If 
it's a bug, it's in the fact that isDynamicArray is used in popFront's 
template constraint. Whether or not Wrapper should be treated as a range is up 
for some debate (implicit conversion tends to cause big problems with template 
constraints, as it becomes far too easy to have constraints which pass and yet 
the function doesn't actually work with the type), but the main problem is 
that front and popFront for arrays don't agree on what they should work with - 
front takes T[] and popFront checks isDynamicArray. So, front works with 
implicit conversion, and popFront doesn't, and that needs to be fixed. But the 
bug is in front/popFront, not isDynamicArray.

I believe that there was a thread on this recently (started by monarch_dodra 
IIRC), so you can look for that discussion for more information if you'd like.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list