std_data_json
std_data_json copied to clipboard
parseJSONValue doesn't work with `in` params / lvalues
The following fails to compile:
static void test(in string a, in string b) {
auto filter = parseJSONValue(a);
auto obj = parseJSONValue(b);
}
And so does the following:
auto filter = parseJSONValue(`{}`);
The current situation is not quite consistent w.r.t. parseJSONStream
here, but parseJSONValue
follows std.conv
:
-
parseJSONValue
takes a reference to an input range and consumes a single JSON value, leaving the rest of the range intact -
toJSONValue
takes an input range by value and expects it to contain exactly one JSON value
Taking this as the basis, parseJSONStream
would actually have to be renamed to toJSONStream
, but since it parses lazily that doesn't seem to capture the meaning very well.
Wouldn't auto ref
be an option here ? From recent N.G. discussions it looks like it's exactly the kind of situation it is used in.
Yes and no. No, because the semantics are also different between the two: to
throws if there is more in the input than a single value (modulo whitespace), while parse
just leaves any excessive contents in the input.