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

downs default_357-line at yahoo.de
Tue Jul 31 18:55:44 PDT 2007


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


More information about the Digitalmars-d-learn mailing list