Idea: Classifications

Xinok xnknet at gmail.com
Fri Jan 5 22:56:58 PST 2007


-- Why not use tuples?
Tuples weren't meant to be used like classifications. Classifications have one main purpose - To be used for comparison. Tuples are more of a data type, a struct almost, they weren't meant to be used in this style.


-- Overloading an Operator
I'm a big fan of convenience, which is the only reason why I posted this idea. IMO, defining a class and overloading the operator is too much work for such a simple concept. It would be easier just to use a function:

bool isprime(int arg){
	static int[] primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29];
	foreach(prime; primes) if(arg == prime) return true;
	return false;
}

And before you say "Then why not use a function?", Simple: You can't use a function at compile time, only during runtime.


-- Using Static If for Multiple Specialization
While it's unlikely to be an issue, when using static if's in templates, it's possible that they can hide declarations if you implicitly instantiate the template.

template func(T){
	static if(is(T == int)) void func(T arg){ } // 'specialized' func
	else void func(T arg){ } // unspecialized func
}

func(35); // Error
func!(int)(35); // OK


-- 'Traits'
A trait is more like an attribute or property. A classification is more like a group.
Also, class != classification



More information about the Digitalmars-d mailing list