[Issue 19982] padLeft usability issues

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 20 02:32:35 UTC 2019


--- Comment #4 from shove <shove at 163.com> ---
The final step in the internal implementation of padLeft is chain() , and
chain() converts multiple different types into a single type that can be
accommodated via CommonType.

alias X = CommonType!(int, long, short);
assert(is(X == long));
alias Y = CommonType!(int, char[], short);
assert(is(Y == void));


static assert(is(ElementType!(typeof("string".padLeft('0', 10))) == uint));
static assert(is(ElementType!(typeof("string".padLeft(dchar('0'), 10))) ==

The corresponding types of these two sentences are transformed as follows:

alias Z1 = CommonType!(char, dchar);
static assert(is(Z1 == uint));
alias Z2 = CommonType!(dchar, dchar);
static assert(is(Z2 == dchar));

So there is no problem with the design here, we can use it flexibly after
mastering this feature.


More information about the Digitalmars-d-bugs mailing list