Amusing D facts: typesafe variadic arrays are lazy!
Jeremie Pelletier
jeremiep at gmail.com
Tue Oct 13 13:56:36 PDT 2009
Chris Nicholson-Sauls wrote:
> downs wrote:
>>
>> Here is a funny consequence of this amusing fact:
>>
>> if you overload opAssign in a struct with lazy T[] dgs..., you can
>> achieve the following syntax
>>
>>
>>> WithFlag(GL_BLEND, true) = WithDepthMask(false) = tex.With =
>>> Quads = {
>>> foreach (i, q; qa) {
>>> float f = 1f*i / qa.length; Color(1f-f, f, 1f);
>>> TexCoord(0f, 0f); Vertex(q.points[0]);
>>> TexCoord(1f, 0f); Vertex(q.points[1]);
>>> TexCoord(1f, 1f); Vertex(q.points[3]);
>>> TexCoord(0f, 1f); Vertex(q.points[2]);
>>> }
>>> };
>
> That's... just beautiful...
>
> -- Chris Nicholson-Sauls
If you forget the fact that he is using GL's immediate mode which is
slooooow, yeah it's beautiful, would be better with an interlaced vertex
buffer :)
Jeremie
More information about the Digitalmars-d
mailing list