On 02/21/2014 04:41 AM, Hannes Steffenhagen wrote:
The specific problem here was when working with std.json.
std.json distinguishes between UINTEGER and INTEGER, so I had code like
static if(is(T : ulong)) {
// must be UINTEGER
} else static if(is(T : long)) {
// can be either INTEGER or UINTEGER
}
I've since found out about isSigned and isUnsigned, still it was mighty
confusing for me that the first case was selected for signed types.
I have something like the following in an experimental std.json code
that converts to JSONValue.
Since std.json uses long for the value, I attempt to detect data loss
when the value is a large ulong:
JSONValue to(Target : JSONValue, T)(T value)
{
/* ... */
} else static if (is (T : long)) {
static if (is (T == ulong)) {
enforce(value <= long.max,
format("Data loss: %s %s cannot fit a long.",
T.stringof, value));
}
json.type = JSON_TYPE.INTEGER;
json.integer = value;
} else static if (is (T : real)) {
Ali