Simple template constraint question
WhatMeWorry via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Sep 19 10:09:46 PDT 2015
Does D provide complete template constraint granularity?
In other words, I want to only accept structs in the template
I've find the isAggregateType which is close but no cigar. Am I
some other filters?
And a more open ended question. Is there a more elegant solution
below function? Maybe a one-liner? I have a knack for making
// Calculate the number of components for openGL generic
// vertex attribute. Must be 1, 2, 3, 4.
// isAggregateType constraint accepts class, union, struct, and
int getNumberComponents(T)(T someStruct) if (isAggregateType!(T))
int members = 0;
foreach (i, member; someStruct.tupleof)
//writefln("Member %s:", i);
//writefln(" type : %s", typeof(member).stringof);
//writefln(" value: %s", member);
More information about the Digitalmars-d-learn