"This is madness!" Red Book OpenGL Example 1-3, done using templates

Don Clugston dac at nospam.com.au
Thu Aug 2 23:34:36 PDT 2007


downs wrote:
> downs wrote:
>> /// A very generic glColor. Supports static arrays.
>> import std.traits;
>> void glColor(T...)(T t) {
>>   static if (T.length==1) { alias T[0] Thingie; const bool 
>> vector=true; alias typeof(t[0][0]) ElemType; }
>>   else { alias T Thingie; const bool vector=false; alias typeof(t[0]) 
>> ElemType; }
>>   const char[] count=Thingie.length.stringof;
>>   static assert(count=="3"||count=="4");
>>   const char[] type=(unsigned!(ElemType)?"u":"")~ElemType.stringof[0];
> Stupid me. I never tested this part for unsigneds.
> Of course, it should be 
> (unsigned!(ElemType)?"u"~ElemType.stringof[1]:ElemType.stringof[0]);
> Sorry.
>  --downs

Still doesn't compile with DMD 1.020.
So basically you're generating the GL headers using metaprogramming?
Crazy stuff. <g>


More information about the Digitalmars-d-learn mailing list