[Issue 1827] Uniform syntax for is(), static if, alias, template definition & static assert
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Feb 12 04:52:57 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1827
------- Comment #3 from aarti at interia.pl 2008-02-12 06:52 -------
continuation for 'alias' thing...
Templates already currently can evaluate to one of two:
1. manifest constant
2. type (symbol)
---------------------
Template which evaluates to manifest constant:
template isRefType(T) {
static if (is(T TYPE == TYPE*) || is(T == class))
const isRefType = true; // or alias true isRefType;
else
const isRefType = false; // or alias false isRefType;
}
Unfortunately syntax:
alias true isRefType;
is not very readable, so maybe it would be worth to introduce
inverted syntax when only one symbol is defined:
alias isRefType = true;
as alternative...
---------------------
It would be in pair with templates which evaluates to type:
Template which evaluates to type:
template arrayElementType(T) {
static if( is( T U : U[] ) )
alias U arrayElementType;
else
static assert(false, "'" ~ T.stringof ~ "' is not an array.");
}
BTW. with alias syntax above template will be not necessary at all, as it would
be probably easier to write:
alias T U : U[];
--
More information about the Digitalmars-d-bugs
mailing list