Idea: Classifications

Chris Nicholson-Sauls ibisbasenji at gmail.com
Fri Jan 5 12:48:58 PST 2007


Xinok wrote:
> 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

It isn't a bad idea.  Although maybe a better term would be "traits" (classification isn't 
bad, just potentially ambiguous with OOP classes).

trait signed (byte, short, int, long);

template temp (T : signed) {}

template tempmulti (T : trait(int, long)) {}

With the same rules as Tuples: either types or data, not both.  There may well be sensible 
ways of making this happen right now with Tuples though, given a little more working out. 
  (Not right now as in with the current compiler, but right now as in hooking existing 
features to each other.)

-- Chris Nicholson-Sauls



More information about the Digitalmars-d mailing list