Impressed

Stuart stugol at gmx.com
Sat Jul 28 02:00:06 PDT 2012


On Saturday, 28 July 2012 at 08:53:43 UTC, Dmitry Olshansky wrote:
> On 28-Jul-12 11:49, Stuart wrote:
>>
>> But as I understand it, for ranges I'd need to write a whole 
>> new class.
>
> struct. Yeah, you need it.
>
>> Here, I'm writing a SINGLE FUNCTION in standard imperative 
>> style.
>
> That implicitly constructs Iterator.
> It's just a sugar. In fact you can do template mixin to 
> generate most of range boilerplate.

I think the basic thrust of my point is: Sugar is good. The 
compiler converting an imperative function into a state-machine 
class is helpful. Having to write it yourself every damn time is 
a pain in the arse.

I've been reading about ranges at 
[http://ddili.org/ders/d.en/ranges.html], and don't understand 
something. Where it says:

    struct StudentRange {
     Student[] students;

     this(School school) {
         this.students = school.students;
     }

     [...code...]

Surely "students" is copied here? Isn't the whole point NOT to 
copy the array? Perhaps it should say:

    this.students = school.students[];

?


More information about the Digitalmars-d mailing list