glz::patch support for all glz::generic_ types#2387
Merged
stephenberry merged 1 commit intomainfrom Mar 20, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add generic_i64 and generic_u64 support to JSON patch functionality
Closes #2385
Summary
The JSON patch module (
patch.hpp) was hardcoded to useglz::generic(f64 mode) throughout. This meant thatglz::generic_i64andglz::generic_u64could not be used with any patch operations, losing integer precision for values beyond whatdoublecan represent.This PR templatizes the entire JSON patch module so that all operations (RFC 6902 patch, RFC 7386 merge patch, and diff) work with any
generic_jsonspecialization.Changes
include/glaze/json/patch.hppis_generic_jsontype trait and concept to detect anygeneric_json<Mode, MapType>specializationpatch_opandpatch_documentintopatch_op_t<GenericType>andpatch_document_t<GenericType>, with backward-compatible aliases (patch_op = patch_op_t<>,patch_document = patch_document_t<>)equal,navigate_to_parent,insert_at,remove_at), operation functions (apply_add/remove/replace/move/copy/test), diff, patch, and merge patch functionsstd::visitindiff_implto usetypename GenericType::object_t/array_tinstead of hardcodedgeneric::types, with a generic else branch that handles all scalar types (double,int64_t,uint64_t,string,bool)not_genericconcept to exclude allgeneric_jsonspecializations (previously only excludedgeneric)tests/json_test/json_patch_test.cppgeneric_i64_patch_testssuite (9 tests): add, replace with precision preservation, diff/patch round-trip, test, move, merge patch, merge diff, patched (non-mutating), patch_json string conveniencegeneric_u64_patch_testssuite (5 tests): add, diff/patch round-trip, test, merge patch, patch_json string convenienceBackward Compatibility
All changes are fully backward compatible. Existing code using
patch_op,patch_document,diff(),patch(),merge_patch(), etc. continues to work without modification. All 64 original tests pass unchanged alongside the 14 new tests (78 total, 300 assertions).