json icon indicating copy to clipboard operation
json copied to clipboard

Add apply*() functions (visitor pattern)

Open falbrechtskirchinger opened this issue 3 years ago • 1 comments

This has been factored out of #3446 but builds upon that PR and needs to be rebased.

Originally, I was looking for a workaround to be able to use std::ranges::sort() with basic_json. std::ranges::sort(j) fails to compile because basic_json doesn't (and can't) satisfy the std:random_access_iterator concept. This PR is the product of this search and adds 3 variants of visitor-style apply*(Fn, Args...) functions to basic_json which invoke a given callable (Fn) with the stored JSON value and any additional arguments (Args...).

(Describe functions, etc.)

To Do:

  • [ ] Exceptions are placeholders. Throw appropriate type, maybe re-word messages, and pick (and document) an ID number.
  • [ ] Complete unit tests.
  • [ ] Update documentation.
  • [ ] Look at discussion #3779. Potential use case?

falbrechtskirchinger avatar Apr 21 '22 11:04 falbrechtskirchinger

Coverage Status

Coverage decreased (-0.02%) to 99.983% when pulling 04b4d79ec22b3b08534bc3191da45232f15a5993 on falbrechtskirchinger:apply into b205361d8652759b6d850a37b227c8d57ee19005 on nlohmann:develop.

coveralls avatar Apr 21 '22 12:04 coveralls