How to removes an variable topmost const. like remove_const in C++.
lili
akozhao at tencent.com
Thu Aug 22 18:50:59 UTC 2019
Hi:
I write a template function is below, that need to remove
const topmost if has.
How to do this?
const int i =3;
println(i);
void println(A...)(A a)
{
char[20] numStr = void;
foreach(v ; a) {
if (is(v.type == byte) || is(v.type == ubyte) ||
is(v.type == short) || is(v.type == ushort) ||
is(v.type == int) || is(v.type == uint) ||
is(v.type == long) || is(v.type == ulong)) {
//did not wirte const types ... again.
ulong n = cast(ulong)v;
bool isNeg = false;
if (v < 0) {
isNeg = true;
if (n != 1<<63)
n = -v;
}
int i=0;
while(n !=0 ) {
numStr[i++] = (n%10) + '0';
n/=10;
}
if (isNeg)
putc('-');
while (--i >= 0)
putc(numStr[i]);
} else if (is(v.type == char*) || is(v.type == const
char*)) {
puts(v);
} else if (is(v.type == bool)) {
puts(v ? "true":"false");
} else if (is(v.type == char)) {
putc(v);
} else {
static assert(false);
}
}
}
More information about the Digitalmars-d-learn
mailing list