simple display (from: GUI library for D)

Adam D. Ruppe destructionator at gmail.com
Fri Apr 8 18:30:59 PDT 2011


bearophile wrote:
> With Color is becomes something like:
> foreach (col; zip(reds, greens, blues))
>    image[x, y] = Color(col.tupleof);

That looks perfectly acceptable to me.

I might add an overload so opIndex can take a tuple too though,
so the zip example is a little easier, but I really prefer the
Color struct.

> I see. But those lambdas are a bit too much large put there. I
> suggest true named function moved elsewhere.
> - Inside the (dchar c) {} a switch seems better.

Yeah, that's what happens when an example grows bigger then
intended without refactoring :P

> - In Wrapped struct why are you using a checkLimits() instead of
> an invariant()?

It's not a check (poorly chosen name I guess!) - it actually
changes the value (wrapping around) when it hits the limit, so
user input never leads to crazy values.

Besides, invariants are generally to check the program for bugs,
rather than external input from the user like used here.


More information about the Digitalmars-d mailing list