Commit graph

752 commits

Author SHA1 Message Date
Niels Lohmann 836b7beca4
Fix CI, again (#4083) 2023-09-07 20:41:12 +02:00
Niels Lohmann ab06fc9951
Fix Clang-Tidy warnings (#4047) 2023-06-08 18:46:48 +02:00
Niels Lohmann a0c1318830
Fix CI + new Doctest (#3985) 2023-05-21 17:23:18 +02:00
Raphael Grimm bbe337c3a3
Prevent memory leak when exception is thrown in adl_serializer::to_json (#3901)
Co-authored-by: barcode <barcode@example.com>
2023-03-08 13:43:45 +01:00
Niels Lohmann 80dfb049b3
Fix warning about moved from object (#3889) 2022-12-18 17:20:30 +01:00
Niels Lohmann 2ca8dabeb9
Remove a magic number (#3888) 2022-12-18 17:04:51 +01:00
Dirk Stolle 4b2c8ce6bc
Fix some typos for n-dimensional arrays (#3767) 2022-09-26 06:23:18 +02:00
Niels Lohmann 58bd97e2b1
Add clang-tools to required tools for ci_static_analysis_clang (#3724)
* 💚 add clang-tools to required tools for ci_static_analysis_clang

* 🚨 update Clang-Tidy warning selection

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings

* 🚨 fix Clang-Tidy warnings (#3738)

*  revert fix

*  revert fix

* 🚨 fix Clang-Tidy warnings (#3739)

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
2022-09-13 12:58:26 +02:00
Florian Albrechtskirchinger 307c053b9b
Add missing <numeric> include (#3719) 2022-08-30 20:55:47 +02:00
Raphael Grimm bed648ca55
Allow custom base class as node customization point (#3110)
Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
Co-authored-by: barcode <barcode@example.com>
2022-08-28 13:59:07 +02:00
Niels Lohmann f7973f46d6
Use official Clang/GCC containers (#3703) 2022-08-27 17:28:50 +02:00
Niels Lohmann 9d69186291
🔖 set version to 3.11.2 2022-08-12 15:04:06 +02:00
Florian Albrechtskirchinger 0e61ee8b07
Restructure inline namespace and allow version component to be disabled (#3683) 2022-08-10 20:24:16 +02:00
Florian Albrechtskirchinger a92ccafd2c
Deprecate json_pointer/string_t comparisons (#3684)
* Deprecate json_pointer/string_t comparisons

* Update documentation
2022-08-07 22:26:59 +02:00
Florian Albrechtskirchinger 31265dc69c
Make json_pointer usable as map key (again) (#3685)
* Make json_pointer usable as map key

* Add unit tests
2022-08-07 14:35:40 +02:00
Florian Albrechtskirchinger 231f3108ff
Amalgamate the forward declaration header (#3679)
* Amalgamate the forward declaration header

* Update CONTRIBUTING and PULL_REQUEST_TEMPLATE

* Update documentation
2022-08-07 13:57:32 +02:00
Florian Albrechtskirchinger dae5412268
Properly constrain non-string json_pointer overloads (#3681)
Thanks, @alex-700, for reminding me.
2022-08-07 13:55:09 +02:00
Florian Albrechtskirchinger 0c7a18374c
Reimplement value() access functions (#3663)
* Reimplement value() access functions

* Merges the 'const char *' with the 'ValueType &&' overloads.
* Fixes ambiguities when default value is 0.
* Fixes 'no matching function' error when specifying ValueType template
  parameter.
* Fixes incorrect template parameter order in previous overloads.

* Add additional value() tests

* Make JSON_MultipleHeaders visible to unit tests

Define the macro JSON_TEST_USING_MULTIPLE_HEADERS to 0/1 depending on
JSON_MultipleHeaders.

* Add type_traits unit test

* Update documentation
2022-08-07 13:54:55 +02:00
Florian Albrechtskirchinger f1e34070d2
Fix 'const' qualifier on bool& has no effect (#3678)
* Fix 'const' qualifier on bool& has no effect

Thanks, @georgthegreat, for pointing out this issue.

* Extend std::vector<bool> unit test
2022-08-07 13:50:08 +02:00
Florian Albrechtskirchinger 9e1a7c85e3
Add json_pointer/string_t equality comparison operators (#3664) 2022-08-05 14:08:27 +02:00
Florian Albrechtskirchinger 32242022f7
Minor BJData fixes (#3637)
* Replace vector/map LUTs in binary_reader with arrays

* Replace string_t::npos in binary_reader
2022-08-03 09:15:37 +02:00
Niels Lohmann f2020da0dd
🔖 set version to 3.11.1 2022-08-01 23:27:58 +02:00
Florian Albrechtskirchinger cbaf1033be
Fix global UDLs (#3646)
* Add ci_test_noglobaludls to CI

* Really default JSON_GLOBAL_UDLS to 1

* Test global UDLs

* Suppress warnings

* Clarify documentation
2022-08-01 22:42:35 +02:00
Niels Lohmann ce0e13ccea
🔖 set version to 3.11.0 2022-07-31 23:19:06 +02:00
Florian Albrechtskirchinger 9aafcbe965
Move UDLs out of the global namespace (#3605)
* Move UDLs into nlohmann::literals::json_literals namespace

* Add 'using namespace' to unit tests

* Add 'using namespace' to examples

* Add 'using namespace' to README

* Move UDL mkdocs pages out of basic_json/

* Update documentation

* Update docset index

* Add JSON_GlobalUDLs CMake option

* Add unit test

* Build examples without global UDLs

* Add CI target
2022-07-31 17:38:52 +02:00
Niels Lohmann 9472ab4f84
Add license header to new files (#3633) 2022-07-31 07:22:22 +02:00
KsaNL fc3e64cbf9
Fixed latest build error in msvc platform (#3630)
* Fixed latest build error in msvc platform

warnings in msvc about mix/max macro while windows.h is used in the project #762

* Update for CI

None

* Update single_include/nlohmann/json.hpp

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
2022-07-30 23:03:09 +02:00
Florian Albrechtskirchinger d909f80960
Add versioned, ABI-tagged inline namespace and namespace macros (#3590)
* Add versioned inline namespace

Add a versioned inline namespace to prevent ABI issues when linking code
using multiple library versions.

* Add namespace macros

* Encode ABI information in inline namespace

Add _diag suffix to inline namespace if JSON_DIAGNOSTICS is enabled, and
_ldvcmp suffix if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON is enabled.

* Move ABI-affecting macros into abi_macros.hpp

* Move std_fs namespace definition into std_fs.hpp

* Remove std_fs namespace from unit test

* Format more files in tests directory

* Add unit tests

* Update documentation

* Fix GDB pretty printer

* fixup! Add namespace macros

* Derive ABI prefix from NLOHMANN_JSON_VERSION_*
2022-07-30 21:59:13 +02:00
Florian Albrechtskirchinger fca1ddda96
Fix patch::add creating nonexistent parents (#3628)
* Fix patch::add creating nonexistent parents

The previous behavior was not in accordance with RFC6902.
Add unit test.

Fixes #3134.

* Fix incorrect JSON patch unit test

Co-authored-by: Hudson00 <yagdhscdasg@gmail.com>
2022-07-30 21:23:55 +02:00
Florian Albrechtskirchinger e3095f636f
Add operator<<(json_pointer) (#3601)
* Add operator<< for json_pointer

* Deprecate json_pointer::operator string_t()

* Update documentation

* Move operator<<(basic_json) example

* Add example

* Add mkdocs-redirects

* Move operator<< and operator>> doc pages out of basic_json/

* Rename JSON pointer operator_string to operator_string_t

* Add unit test
2022-07-28 22:12:23 +02:00
Florian Albrechtskirchinger a87c1885cb
Re-add value_type detection to distinguish string types (#3604)
* Re-add value_type detection to is_constructible_string_type trait

* Add value_type detection to from_json for strings
2022-07-28 21:52:23 +02:00
Florian Albrechtskirchinger a714381a5f
Use swap() by ADL (#3609)
* Use swap() by ADL

* Add type to swap() exception messages
2022-07-28 21:51:45 +02:00
Niels Lohmann dbfd33a70a
Add assertion if nullptr is passed to parse function (#3593)
Addresses #3584
2022-07-23 01:26:51 +02:00
Wolf Vollprecht 09fb4819ff
add patch_inplace function (#3581)
* add patch_inplace function to json class

* add documentation

* fix up docs
2022-07-21 16:27:59 +02:00
Niels Lohmann 527da54dcb
Use REUSE framework (#3546)
* 📄 add licenses

* 👷 add REUSE compliance check

* 📝 add badge for REUSE

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
2022-07-20 12:38:07 +02:00
Romain Reignier d4daaa897f
Optimize output vector adapter write (#3569)
* Add benchmark for cbor serialization and cbor binary data serialization

* Use std::vector::insert method instead of std::copy in output_vector_adapter::write_characters

This change increases a lot the performance when writing lots of binary data.
2022-07-08 08:12:00 +02:00
Florian Albrechtskirchinger 7d361ec8ef
Add overloads for more key types to ordered_map and fix ordered_map::erase(first, last) with first == last (#3564)
* Add overloads for more key types to ordered_map

Add overloads to accept additional key types defined by type trait
detail::is_usable_as_key_type to ordered_map.
The same key types that can be used with json can now also be used with
ordered_json.

* Fix ordered_map::erase(first, last) with first == last

* Modify element access unit test to also test ordered_json
2022-07-04 19:58:19 +02:00
郑少锟 87cda1d664
Use std::iterator_traits to extract iterator_category (#3544)
* Use `std::iterator_traits` to extract `iterator_category`

In third-party STL implementations, `array_t::iterator` might be a pointer (e.g., `vector` in [EASTL](https://github.com/electronicarts/EASTL)) rather than a class, in which case directly using `array_t::iterator::iterator_category` is invalid. This commit fixes it with `std::iterator_traits`, which handles pointers correctly.

* add the changes to the single-header version
2022-06-18 19:14:03 +02:00
Qianqian Fang 13730235f2
BJData dimension length can not be string_t::npos, fix #3541 (#3543)
* BJData dimension length can not be string_t::npos, fix #3541

* handle error messages on 32bit machine

* add explanation to why size can not be string_t::npos

* add test cases to 32bit unit test

Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
2022-06-18 19:12:22 +02:00
Richard Hozák f6acdbec2c
Allow disabling default enum conversions (#3536) 2022-06-16 19:34:32 +02:00
Florian Albrechtskirchinger e80945da2c
CI: Enable 32bit unit test (3) (#3532)
* Enable JSON_MultipleHeaders by default

* CI: Add single-header build

* CI: Enable 32bit unit test

* Fix "-Wuseless-cast" warnings

* Remove coverage exclusion

* Fix 32bit test case
2022-06-14 08:54:12 +02:00
Florian Albrechtskirchinger 9c31d54389
Add to_json() for std::vector<bool>::reference (#3534) 2022-06-13 13:21:55 +02:00
Niels Lohmann af34396129
Use new CI image (#3528)
* ⬆️ use new CI image

* ⬆️ use new CI image

* 🚨 fix warning

* 🔧 remove duplicate warning flags

* 💚 fix test

* 📝 update compiler versions
2022-06-12 14:31:07 +02:00
Florian Albrechtskirchinger 48a102c2c5
Fix ndarray dimension signedness, fix ndarray length overflow (2); add 32bit unit test (#3523)
* Fix ndarray dimension signness, fix ndarray length overflow, close #3519

* detect size overflow in ubjson and bjdata

* force reformatting

* Fix MSVC compiler warning

* Add value_in_range_of trait

* Use value_in_range_of trait

* Correct 408 parse_errors to out_of_range

* Add 32bit unit test

The test can be enabled by setting JSON_32bitTest=ON.

* Exclude unreachable lines from coverage

Certain lines are unreachable in 64bit builds.

Co-authored-by: Qianqian Fang <fangqq@gmail.com>
2022-06-09 08:22:58 +02:00
ivanovmp 7c65b5cdbd
Update json.hpp (#3499)
* Update json.hpp

* Remove a space
2022-06-06 13:01:46 +02:00
Florian Albrechtskirchinger 7a6e28acfa
Add assertion to converting constructor (#3517)
The converting basic_json constructor can inadvertently change the value
type of its parameter. Assert that both basic_json values are of the
same value type after conversion.
2022-06-03 21:05:44 +02:00
Qianqian Fang 046927cc29
Fix nlohmann/json#3513, explain is_ndarray flag (#3514)
* Fix nlohmann/json#3513, explain is_ndarray flag

* add test for ndarray size following H
2022-06-03 08:51:33 +02:00
Florian Albrechtskirchinger 6b97599a27
Fix C++20/gcc-12 issues (Part 2) (#3446)
* Add C++20 3-way comparison operator and fix broken comparisons

Fixes #3207.
Fixes #3409.

* Fix iterators to meet (more) std::ranges requirements

Fixes #3130.
Related discussion: #3408

* Add note about CMake standard version selection to unit tests

Document how CMake chooses which C++ standard version to use when
building tests.

* Update documentation

* CI: add legacy discarded value comparison

* Fix internal linkage errors when building a module
2022-05-29 13:08:06 +02:00
Qianqian Fang ede6667858
Prevent ndarray size vector from recursive use, fix nlohmann/json#3503 (#3505)
* Prevent ndarray size vector from recursive use, fix nlohmann/json#3503

* fix ci error

* complete coverage

* add missing coverage

* fix style issue in added test
2022-05-23 06:07:22 +02:00
Qianqian Fang 41226d0a03
prevent ndarray dimension vector from recusive array, nlohmann/json#3500 (#3502) 2022-05-20 09:41:51 +02:00