alias this + std.array.popFront

Tobias Pankrath tobias at pankrath.net
Sat Mar 30 01:48:56 PDT 2013


On Saturday, 30 March 2013 at 00:23:17 UTC, Jonathan M Davis 
wrote:
> 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

Yes, you are most probably right that the bug is not in 
isDynamicArray. However DynamicArrayTypeOf and isDynamicArray are 
rather inconsistent since DynamicArrayTypeOf does not check exact 
types.


More information about the Digitalmars-d-learn mailing list