Commit graph

58 commits

Author SHA1 Message Date
Niels Lohmann 9cca280a4d
JSON for Modern C++ 3.11.3 (#4222) 2023-11-28 22:36:31 +01:00
Colby Haskell 1d597743d8
Fix char_traits deprecation warning (#4179) 2023-11-27 06:51:25 +01:00
Niels Lohmann f56c6e2e30
Update documentation for the next release (#4216) 2023-11-26 15:51:19 +01:00
Niels Lohmann 836b7beca4
Fix CI, again (#4083) 2023-09-07 20:41:12 +02:00
Niels Lohmann 9d69186291
🔖 set version to 3.11.2 2022-08-12 15:04:06 +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
Niels Lohmann f2020da0dd
🔖 set version to 3.11.1 2022-08-01 23:27:58 +02:00
Niels Lohmann ce0e13ccea
🔖 set version to 3.11.0 2022-07-31 23:19:06 +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 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
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
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
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
Florian Albrechtskirchinger bdc21ad1a7
Add build step for ICPC (with fixes) (#3465)
* ⬆️ Doctest 2.4.7

* 👷 add CI step for ICPC

* 👷 add CI step for ICPC

* 👷 add CI step for ICPC

* ⬇️ downgrade to Doctest 2.4.6

* 👷 add CI step for ICPC

* 👷 add CI step for ICPC

* 👷 add CI step for ICPC

* 👷 add CI step for ICPC

* 👷 add CI step for ICPC

* 🔇 suppress warning #2196: routine is both "inline" and "noinline"

* Re-enable <filesystem> detection on ICPC

* Limit regression test for #3070 to Clang and GCC >=8.4

* Disable deprecation warnings on ICPC

* Disable regression test for #1647 on ICPC (C++20)

* Fix compilation failure of regression test for #3077 on ICPC

* Disable wstring unit test on ICPC

Fixes:
  error 913: invalid multibyte character sequence

* Add ICPC to README

Co-authored-by: Niels Lohmann <mail@nlohmann.me>
2022-05-01 22:46:45 +02:00
Florian Albrechtskirchinger 5352856f04
Implement support for string_view (attempt no. 3) (#3423)
* Add key_compare member to ordered_map

* Replace == with key_compare in ordered_map

* Expose the actual comparison function used by object_t

nlohmann::ordered_map uses a different comparison function than the one
provided via template parameter.
* Introduce a type trait to detect if object_t has a key_compare member.
* Rename object_comparator_t to default_object_comparator_t.
* Add object_comparator_t to be conditionally defined as
  object_t::key_compare, if available, or default_object_comparator_t
  otherwise.
* Update the documentation accordingly.

Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>

* Add type traits to check if a type is usable as object key

Add type trait to check:
* if a type is a specialization of a template.
* if a type is a json_pointer.
* if a type is a basic_json::{const_,}iterator.
* if two types are comparable using a given comparison functor.
* if a type is comparable to basic_json::object_t::key_type.
* if a type has a member type is_transparent.
* if a type is usable as object key.
* if a type has an erase() function accepting a given KeyType.

Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>

* Rework basic_json element access to accept more key types

Rework basic_json element access member functions and operators to
accept any type that meets the requirements defined by type trait
detail::is_usable_as_key_type.

Member functions and operators:
* at()
* operator[]
* value()
* erase()
* find()
* count()
* contains()

Update documentation to reflect these changes.

Add unit tests to excercise the new functions using std::string_view.

Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>

Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
2022-04-29 21:40:02 +02:00
Florian Albrechtskirchinger 616caea27a
Re-template json_pointer on string type (#3415)
* Make exception context optional

Change exception context parameter to pointer and replace context with
nullptr where appropriate.

* Support escaping other string types

* Add string concatenation function

Add variadic concat() function for concatenating char *, char, and
string types.

* Replace string concatenations using + with concat()

* Template json_pointer on string type

Change json_pointer from being templated on basic_json to being
templated on string type.

* Add unit test for #3388

Closes #3388.

* Fix regression test for #2958

* Add backwards compatibility with json_pointer<basic_json>

* Update json_pointer docs

* Allow comparing different json_pointers

* Update version numbers
2022-04-12 14:18:16 +02:00
DarkZeros 6121dbbe02
Avoid clash with Arduino defines (#3338)
* Avoid clash with Arduino defines

* Arduino defines B0/B1 in "binary.h"
     #define B0 0
     #define B1 1
  This clashes with names of the template
  variables in conjuction

* Renaming them to "B" rather than "B1"
  Now it can be used as-is in Arduino projects

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Daniel Ansorregui <d.ansorregui@samsung.com>
Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
2022-04-03 18:33:33 +02:00
Théo DELRIEU 0e694b4060
fix std::filesystem::path regression (#3073)
* meta: rework is_compatible/is_constructible_string_type

These type traits performed an incorrect and insufficient check.

Converting to a std::filesystem::path used to work by accident thanks to
these brittle constraints, but the clean-up performed in #3020 broke them.

* support std::filesystem::path

Fixes #3070
2021-10-14 19:19:46 +02:00
Théo DELRIEU 80df5e8de6
meta: fix is_compatible/constructible traits (#3020)
The previous version relied on the existence of an 'iterator' type.

As mentioned in comments, this is not the proper way to do it and
causes issues with certain types (e.g. views from range-v3).

Add a 'is_range' trait that properly detects the return type of
'begin'/'end', and use it in instead.
2021-10-07 12:32:25 +02:00
Niels Lohmann c753165db6
Fix parent update for diagnostics with ordered_json (#2963)
🐛 fix parent update for diagnostics with ordered_json
2021-08-22 20:30:20 +02:00
Niels Lohmann 9a459e1bd5
🚨 fix useless-cast warnings 2021-07-30 15:20:22 +02:00
Niels Lohmann 7feb2c20cf
🚨 fix useless-cast warnings 2021-07-30 14:48:25 +02:00
Louis Dionne b0e5965d71 Properly constrain the basic_json conversion operator
Fixes #2491
2021-07-19 11:16:27 -04:00
Anthony VH 130382f2a9 Remove comment about GCC commit which didn't really relate to the code. 2021-01-24 20:02:24 +01:00
Anthony VH 848927ae90 Updated comments as requested. 2021-01-23 18:24:47 +01:00
Anthony VH 6ebf274ca0 Add internal version of is_default_constructible to work around LWG 2367. 2021-01-12 18:28:00 +01:00
Anthony VH 1e825e4f92 Add support for deserialization of STL containers of non-default constructable types (fixes #2574). 2021-01-09 00:08:27 +01:00
Niels Lohmann dfedefb993
🚨 fix warnings 2020-12-26 17:56:16 +01:00
Niels Lohmann 94d177e09a
📄 clarify license 2020-12-14 14:58:59 +01:00
Théo DELRIEU 74b446f5fd
add a switch to enable implicit conversions (defaults to true)
wrap implicit conversions tests around the JSON_USE_IMPLICIT_CONVERSIONS
macro
2020-07-22 10:49:01 +02:00
Niels Lohmann 8d295235a5
🔥 remove unused boolean_operators.hpp header 2020-07-11 19:20:44 +02:00
Niels Lohmann 0498202a03
🎨 replace alternative operators (and, not, or) 2020-06-03 14:20:36 +02:00
Niels Lohmann 9adb1c0235
🏁 do not include <ciso646> unless old MSVC is used #2089 2020-05-07 09:43:41 +02:00
Artöm Bakri Al-Sarmini 70be9751cd typo fix 2020-04-12 23:42:26 +03:00
Artöm Bakri Al-Sarmini ec955f08b4 Templatize basic_json ctor from json_ref 2020-04-12 22:32:39 +03:00
Camille Bégué 8b686b30eb Add restriction for tuple specialization of to_json
This commit fix the issue #1825

Signed-off-by: Camille Bégué <c.begue@samsung.com>
2019-11-04 09:57:16 +01:00
Théo DELRIEU 2806b201a8
make sure values are overwritten in from_json overloads
Caused unexpected behaviors when using get_to with values previously
set.

Fixes !1511
2019-04-01 17:47:42 +02:00
Niels Lohmann b8451c236f
🚨 fixed warnings 2019-03-17 12:01:49 +01:00
David Avedissian f665a92330 Implement SFINAE friendly iterator_traits and use that instead. 2018-11-07 18:39:25 +00:00
Niels Lohmann 8cee0e38d9
🚑 fixed #1319 2018-10-30 17:29:05 +01:00
Niels Lohmann d2e4f0b0d9
✏️ fixed some typos 2018-10-28 14:20:20 +01:00
Niels Lohmann e2c5913a50
🚧 some changes to the BSON code
- added fuzz testers
- added some reference files
- made an exception text more clear
2018-10-24 15:43:37 +02:00
Théo DELRIEU a946dfc19c
add a note to maintainers in type_traits.hpp 2018-10-17 12:03:10 +02:00
Théo DELRIEU 45c8af2c46
add new is_constructible_* traits used in from_json
is_compatible_* traits were used in from_json, but it made no sense
whatsoever.

It used to work because of non-SFINAE correctness + json_ref
unconstrained variadic template constructor.

SFINAE checks are becoming quite complex, we need a specification of
some sort describing:

* which concepts the library uses
* how the conversion to/from json works in detail

Having such a specification would really help simplifying the current
code (as well as having meaningful checks).

Fixes !1299
2018-10-16 14:00:34 +02:00
Niels Lohmann 858e75c4df
🚨 fixed some clang-tidy warnings 2018-10-07 18:39:18 +02:00
Théo DELRIEU 4e52277b70
Fix issue #1237
* Make the conversion operator SFINAE correct.
* Workaround a GCC bug with some traits in type_traits.hpp

The first bullet-point implies that every `get`/`get_ptr` be SFINAE
correct as well.
2018-09-20 10:33:14 +02:00
Théo DELRIEU aea648bb7a
remove now-useless traits. check for is_basic_json where needed 2018-09-07 14:10:39 +02:00
Théo DELRIEU f7c8a2145a
refactor from/to_json(CompatibleArrayType) 2018-09-07 12:18:04 +02:00