Idea: Classifications

Xinok xnknet at gmail.com
Fri Jan 5 11:38:00 PST 2007


Basically, classifications are a set of aliases which can be used for comparison, during compile time or runtime. Classifications are different from tuples because tuples are a data type.

classify signed(byte, short, int, long);
classify unsigned(ubyte, ushort, uint, ulong);
classify intset(signed, unsigned); // You can use classifications in classifications

Classifications could also be used with variable types:
classify prime(2, 3, 5, 7, 11, 13, 19, 23, 29);

What I meant about how they could be used for comparisons:
Compile time:
template temp(T : signed){ } // Classifications could be a good way to enable multiple specialization
template temp(int V : prime){ }
static if(is(V == prime))

Run time:
int val;
if(val == prime){ } // This would require an invisible loop to compare the variable to all the values in the classification
if(val != prime){ }

Multiple Specialization:
I believe you shouldn't have to declare a separate classification to enable multiple specialization.
template temp(T : classify(int, long)){ }


I believe my terminology is correct for 'classify' and 'classification':
Classify : Arrange or order by classes or categories
Classification : A group of people or things arranged by class or category



More information about the Digitalmars-d mailing list