Idea: Classifications
Witold Baryluk
baryluk at mpi.int.pl
Fri Jan 5 12:16:11 PST 2007
Dnia Fri, 05 Jan 2007 14:38:00 -0500
Xinok <xnknet at gmail.com> napisał/a:
> Basically, classifications are a set of aliases which can be used for
> comparison, during compile time or runtime.
Interesting idea.
> What I meant about how they could be used for comparisons:
> Compile time:
> template temp(T : signed){ } // Classifications could be a good way
or mayby
template isSigned(T) {
static if (is(T == int)) { ; }
else static if (is(T == long)) { ; }
else static assert(false, "inproper type");
}
template temp(T) {
mixin Check!(T);
...
}
longer, but not so bad, once created.
Mayby someone will post here better implementation,
probably using TypeTuples.
>
> Run time:
> int val;
> if(val == prime){ }
You can use operator overloading.
Or if you realy need your kind of classification,
i suggest noted used operator like
if (classify(val == prime))
or
if (val ofclass prime)
you can also create similar tamplete, for value classyfication:
use static table, and mixin foreach, or unrool it useing static foreach,
or use better algoritm.
Any other exmples, that eventually will be hard to implement in other
way?
--
Witold Baryluk
More information about the Digitalmars-d
mailing list