danielaparker / jsoncons

A C++, header-only library for constructing JSON and JSON-like data formats, with JSON Pointer, JSON Patch, JSON Schema, JSONPath, JMESPath, CSV, MessagePack, CBOR, BSON, UBJSON
https://danielaparker.github.io/jsoncons
Other
726 stars 164 forks source link

Allow jmespath to be const qualified #530

Closed nnathan closed 3 months ago

nnathan commented 3 months ago

I would like to see the ability to allow const reference to a jmespath_expression, to ensure that it's read-only and allow the compiler to do any optimisations.

It appears that the jmespath_expression::evaluate() are not const methods and therefore preventing making a useful const reference.

I was a bit concerned that the jmespath_expression was mutating itself each evaluate, but after applying a const to the evaluate() methods, and then made the jmespath_expression a const reference, it didn't seem to have any issue.

danielaparker commented 3 months ago

You're right, evaluate() should be const, it never mutates the state of the jmespath_expression. Fixed on master.

nnathan commented 3 months ago

Much appreciated, thanks for the quick turn around. I'll leave it up to you if you want to close the request.