digitalmars.D.learn - alias this + std.array.popFront
- Tobias Pankrath (9/9) Mar 29 2013 Hello,
- Tobias Pankrath (5/14) Mar 29 2013 The reason seems to be that, while is(DynamicArrayTypeOf!Wrapper
- Jonathan M Davis (15/36) Mar 29 2013 No, it is most definitely _not_ a bug in isDynamicArray. The isX traits ...
- Tobias Pankrath (6/57) Mar 30 2013 Yes, you are most probably right that the bug is not in
- monarch_dodra (6/10) Mar 30 2013 http://forum.dlang.org/thread/xhzojyrrcidusvreupsc@forum.dlang.org
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!
Mar 29 2013
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.
Mar 29 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: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 DavisHello, 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.
Mar 29 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: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.On Friday, 29 March 2013 at 22:13:31 UTC, Tobias Pankrath wrote: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 DavisHello, 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.
Mar 30 2013
On Saturday, 30 March 2013 at 00:23:17 UTC, Jonathan M Davis wrote: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.http://forum.dlang.org/thread/xhzojyrrcidusvreupsc forum.dlang.org "alias this and array popFront: is this a bug?" The similarity in code snippet is uncanny. Kenji seems to have jumped on the issue, and fixed it exactly according to suggestion.
Mar 30 2013