is() and const
Andrea Fontana
nospam at example.com
Wed Jul 18 01:43:23 PDT 2012
Run this code:
class PP {}
void what(T)(T val)
{
static if (is(T == int)) writeln ("T == int");
static if (is(T == const(int))) writeln ("T == const(int)");
static if (is(T : int)) writeln ("T : int");
static if (is(T == PP)) writeln ("T == PP");
static if (is(T == const(PP))) writeln ("T == const(PP)");
static if (is(T : PP)) writeln ("T : PP");
}
void main(string[] args)
{
const int aa = 10;
int ab;
const PP ba = new PP;
PP bb = new PP;
writeln("- Testing const(int)");
what(aa);
writeln();
writeln("- Testing int");
what(ab);
writeln();
writeln("- Testing const(PP)");
what(ba);
writeln();
writeln("- Testing PP");
what(bb);
writeln();
return;
}
It says:
- Testing const(int)
T == const(int)
T : int
- Testing int
T == int
T : int
- Testing const(PP)
T == const(PP)
- Testing PP
T == PP
T : PP
So:
const(int) : int <-- true
const(PP) : PP <-- false
Is this behaviour correct?
And how can I check if T is of a certain class ignoring consts (and
avoiding double checks)?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20120718/6d1729bb/attachment.html>
More information about the Digitalmars-d-learn
mailing list