December 05, 2016 Re: wrong isInputRange design | ||||
---|---|---|---|---|
| ||||
Posted in reply to rumbu | On Sunday, 4 December 2016 at 11:18:56 UTC, rumbu wrote: > Yes, this is the same workaround I found, but that does not solve the fact that the following code does not compile: While it may be too late to redeem Phobos and its handling of arrays as ranges, it is worth noting that in the library I've been working on the `isRange` template behaves like you're expecting. In mach, `front` and `popFront` and `empty` are not defined for strings; rather, functions that accept ranges also accept types that ranges can be made to enumerate, including strings and other arrays. If you really wanted an `isInputRange` that behaves like you're wanting, it's only a 6 line template that you would have to interject in your code. enum bool isInputRange(T) = is(typeof({ T range = T.init; if(range.empty){} auto element = range.front; range.popFront(); })); https://github.com/pineapplemachine/mach.d |
December 06, 2016 Re: wrong isInputRange design | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | On Monday, 5 December 2016 at 21:51:28 UTC, pineapple wrote:
>
> https://github.com/pineapplemachine/mach.d
I love that a few of the subfolders have a Readme.md so that I don't have to dig in to anything to get an overview.
|
December 06, 2016 Re: wrong isInputRange design | ||||
---|---|---|---|---|
| ||||
Posted in reply to pineapple | On Monday, 5 December 2016 at 21:51:28 UTC, pineapple wrote: > On Sunday, 4 December 2016 at 11:18:56 UTC, rumbu wrote: --- > > If you really wanted an `isInputRange` that behaves like you're wanting, it's only a 6 line template that you would have to interject in your code. > > enum bool isInputRange(T) = is(typeof({ > T range = T.init; > if(range.empty){} > auto element = range.front; > range.popFront(); > })); > > https://github.com/pineapplemachine/mach.d My post was about a wrong design decision which generates a compiler error just with one symbol import. If I didn't know how to solve this, I would probably post in the learn section :) After I read the Jonathan's explanations, I understood that it's my fault, one must guess which is the proper way to use a standard library, so I didn't bother to continue the discussion. Anyway, you have a very nice library that just proves my point that a better design is possible: the "asrange" solution for arrays is very elegant. Finally, for my library I decided to completely ignore the range concept, I just check for isIterable and do my processing in a foreach loop. |
Copyright © 1999-2021 by the D Language Foundation