std_data_json icon indicating copy to clipboard operation
std_data_json copied to clipboard

parseJSONValue doesn't work with `in` params / lvalues

Open Geod24 opened this issue 9 years ago • 3 comments

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(`{}`);

Geod24 avatar Jun 23 '15 13:06 Geod24

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.

s-ludwig avatar Jun 25 '15 06:06 s-ludwig

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.

Geod24 avatar Jun 25 '15 11:06 Geod24

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.

s-ludwig avatar Jun 25 '15 11:06 s-ludwig