On Monday, 28 September 2015 at 07:02:35 UTC, Marco Leise wrote:
Am Tue, 18 Aug 2015 09:05:32 +0000
schrieb "Marc Schütz" <schue...@gmx.net>:

Or, as above, leave it to the end user and provide a `to(T)` method that can support built-in types and `BigInt` alike.

You mean the user should write a JSON number parsing routine
on their own? Then which part is responsible for validation of
JSON contraints? If it is the to!(T) function, then it is
code duplication with chances of getting something wrong,
if it is the JSON parser, then the number is parsed twice.
Besides, there is a lot of code to be shared for every T.

No, the JSON type should just store the raw unparsed token and implement:

    struct JSON {
        T to(T) if(isNumeric!T && is(typeof(T("")))) {
            return T(this.raw);
        }
    }

The end user can then call:

    auto value = json.to!BigInt;

Reply via email to