Re: Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-27 Thread aliak via Digitalmars-d-learn
On Friday, 26 January 2018 at 23:15:41 UTC, Simen Kjærås wrote: The function is called fill, and assigns a value to every element in the range. If a[0] = false compiles, we also want a.fill(false) to compile. It's simply testing that, rather than caring about the exact type of the elements.

Re: Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-26 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 26 January 2018 at 15:33:03 UTC, aliak wrote: On Friday, 26 January 2018 at 14:35:25 UTC, Meta wrote: On Friday, 26 January 2018 at 14:16:04 UTC, aliak wrote: 1) I've seen some phobos code checking for assignability like this: is(typeof(range.front = false)) ... is that an advan

Re: Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-26 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 26 January 2018 at 14:16:04 UTC, aliak wrote: It basically steps through in a stride and sets the checkpoints to false. C++: template N> void mark(It begin, It end, N step) { assert(begin != end) *begin = false; while (end - begin > step) { begin = begin + step; *begin

Re: Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-26 Thread Meta via Digitalmars-d-learn
On Friday, 26 January 2018 at 14:16:04 UTC, aliak wrote: 1) I've seen some phobos code checking for assignability like this: is(typeof(range.front = false)) ... is that an advantage of that over hasAssignableElements? Or is that just basically combining constraints 3 and 4 which I have abo

Re: Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-26 Thread aliak via Digitalmars-d-learn
On Friday, 26 January 2018 at 14:59:09 UTC, Simen Kjærås wrote: what is N here? You're declaring it to be an int value in the template<> definition, and then use it as a type in the function definition. Oops again :) Should've been typename N (where N is some integral type). Not exactly. ra

Re: Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-26 Thread aliak via Digitalmars-d-learn
On Friday, 26 January 2018 at 14:35:25 UTC, Meta wrote: On Friday, 26 January 2018 at 14:16:04 UTC, aliak wrote: 1) I've seen some phobos code checking for assignability like this: is(typeof(range.front = false)) ... is that an advantage of that over hasAssignableElements? Or is that just

Re: Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-26 Thread aliak via Digitalmars-d-learn
On Friday, 26 January 2018 at 14:16:04 UTC, aliak wrote: range.front = false; while (!range.empty) { range.popFrontN(N); range.front = false; } } Oops, this should be: while (!range.empty) { range.front = false; range.popFrontN(N); }

Rewriting a c++ template to D (replacing iterator with ranges "properly")

2018-01-26 Thread aliak via Digitalmars-d-learn
It basically steps through in a stride and sets the checkpoints to false. C++: template void mark(It begin, It end, N step) { assert(begin != end) *begin = false; while (end - begin > step) { begin = begin + step; *begin = false; } } For D this is what I figured would be the wa