August 22, 2019 How to removes an variable topmost const. like remove_const in C++. | ||||
---|---|---|---|---|
| ||||
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); } } } |
August 22, 2019 Re: How to removes an variable topmost const. like remove_const in C++. | ||||
---|---|---|---|---|
| ||||
Posted in reply to lili | On Thursday, 22 August 2019 at 18:50:59 UTC, lili wrote: > Hi: > I write a template function is below, that need to remove const topmost if has. > How to do this? https://dlang.org/phobos/std_traits.html#Unqual |
Copyright © 1999-2021 by the D Language Foundation