Why would is(T == struct) be true but !isBuiltinType!T be false?
This seems highly inconsistent. If T is a struct, it is not a
builtin type, and if T is int (also making the condition false),
then Property should never have been passed as a struct, but as
the int gotten via the alias.
On Thursday, 15 November 2012 at 14:52:41 UTC, eskimo wrote:
:-) Indeed, that is the only thing that surprised me too (but
not as
much as in another language, because of D's capabilities). The
solution
I think is this overload found in std.format of formatValue:
void formatValue(Writer, T, Char)(Writer w, auto ref T val, ref
FormatSpec!Char f)
if ((is(T == struct) || is(T == union)) && (hasToString!(T,
Char) || !
isBuiltinType!T) && !is(T == enum))
-> Its body implements the generic print for structs. It either
calls
the structs toString() method if available or if it is a range
it uses
formatRange() otherwise it prints its type name with its
contained
values.
But as you can see the templates requirement states
!isBuiltinType!T, so
in case of your alias this to an int, it won't be used. So the
implementer of this method most likely had taken into account
the
possibility of an alias this to a built in type.
Btw., I love D's readability, it was really easy to find this
and to
understand what it does.
Best regards,
Robert