json
json copied to clipboard
Add apply*() functions (visitor pattern)
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?