47 Commits
Author SHA1 Message Date
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
Théo DELRIEU 797329315a add a CI job for explicit conversions on every os 2020-07-22 10:49:01 +02: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
Théo DELRIEU d66abda4ee tests: fix coverage 2019-04-03 12:34:15 +02:00
Théo DELRIEU e6e6805c6c add built-in array support in get_to 2019-04-01 17:47:45 +02: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
Théo DELRIEU 7b961368d5 recommend using explicit from JSON conversions 2018-11-20 14:14:07 +01: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
Théo DELRIEU 11fecc25af add constraints for variadic json_ref constructors
Fixes #1292
2018-10-12 10:54:58 +02:00
Théo DELRIEU 521fe49fec Add basic_json::get_to function.
Takes an lvalue reference, and returns the same reference.

This allows non-default constructible types to be converted without
specializing adl_serializer.
This overload does not require CopyConstructible either.

Implements #1227
2018-09-28 11:25:23 +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 4b4bbceebf make from_json SFINAE-correct 2018-09-07 14:10:37 +02:00
Théo DELRIEU f7971f04a5 make to_json SFINAE-correct 2018-09-07 12:18:04 +02:00
Théo DELRIEU f7c8a2145a refactor from/to_json(CompatibleArrayType) 2018-09-07 12:18:04 +02:00
Théo DELRIEU 628f76729e do not check for compatible_object_type in compatible_array_type 2018-09-07 12:18:03 +02:00
Théo DELRIEU 29f72966c3 refactor is_compatible_type, remove conjunction & co 2018-09-07 12:18:03 +02:00
Théo DELRIEU 77967e6548 refactor is_compatible_integer_type 2018-09-07 12:18:03 +02:00
Théo DELRIEU 13760857ff refactor is_compatible_array_type 2018-09-07 12:18:02 +02:00
Théo DELRIEU 924e95c6e8 refactor is_compatible_string_type 2018-09-07 12:18:02 +02:00
Théo DELRIEU e84195ab7b refactor is_compatible_object_type 2018-09-07 12:18:02 +02:00
Théo DELRIEU b59c3367c9 use detected instead of has_* traits 2018-09-07 12:17:59 +02:00
Théo DELRIEU 1ea8cd128c fix void_t for older compilers 2018-09-07 12:17:33 +02:00
Théo DELRIEU 0cc3db4f15 add static_asserts on SAX interface 2018-08-16 11:59:57 +02:00
Théo DELRIEU 38f8a51a8f use abstract sax class in parser tests 2018-08-16 11:59:49 +02:00
Théo DELRIEU 9bbb133094 remove no_limit constant and default values 2018-08-16 11:59:05 +02:00
Théo DELRIEU 442886d040 use templates in the sax interface instead of virtuals 2018-08-16 11:58:52 +02:00
Théo DELRIEU f6febbe359 split meta.hpp, add detected_t (used to define concepts) 2018-08-16 11:58:42 +02:00
Théo DELRIEU 2c920a1032 run make amalgamate 2018-06-18 15:14:10 +02:00
Théo DELRIEU 2b37d7ed86 from_json: add overload for std::unordered_map
Fixes #1133
2018-06-18 15:14:10 +02:00
Théo DELRIEU 299469cfd5 from_json: add missing template arguments for std::map 2018-06-18 10:52:11 +02:00
Théo DELRIEU c5e63fd684 Provide a from_json overload for std::map
This overload is chosen only when BasicJsonType::string_t
is not constructible from std::map::key_type.

Currently, converting a map to json treats it as an array of pairs.

fixes #1079
2018-05-28 11:06:24 +02:00
Théo DELRIEU 8711ec6034 support construction from other basic_json types
Before this patch, `basic_json` types with different template arguments
were treated as `CompatibleArrayType`. Which sometimes leads to recursive
calls and stack overflows.

This patch adds a constructor and a `get` overload to deal with
different `basic_json` types.
2018-02-27 16:48:09 +01:00
Théo DELRIEU c22f2d41f3 missing CHECK_NOTHROW in unit-udt 2018-02-27 11:09:53 +01:00
Théo DELRIEU 01d6118828 Fix constraints on from_json(CompatibleArrayType)
Fixes #924
2018-02-12 15:37:33 +01:00
Théo DELRIEU 41db7cd818 Make the coveralls job use the multiple header version 2018-02-12 10:23:33 +01:00
Théo DELRIEU 14cd019861 fix cmake install directory (for real this time)
* Rename 'develop' folder to 'include/nlohmann'
* Rename 'src' folder to 'single_include/nlohmann'
* Use <nlohmann/*> headers in sources and tests
* Change amalgamate config file
2018-02-01 11:06:51 +01:00
Théo DELRIEU dcee778c1e fix sfinae on basic_json UDT constructor
Avoid compiler errors when performing SFINAE checks on basic_json
and incomplete types.
2018-01-17 12:17:38 +01:00
Théo DELRIEU 541ee62a05 cmake: use BUILD_INTERFACE/INSTALL_INTERFACE in target_include_directories 2017-12-05 11:27:03 +01:00
Théo DELRIEU c9a02cbc59 to/from_json: add a MSVC-specific static_assert to force a stacktrace 2017-12-05 10:52:55 +01:00
Théo DELRIEU 08d781058c add from_json support for std::array 2017-06-19 12:03:38 +02:00
Théo DELRIEU c98364834f remove std::pair support 2017-06-13 11:11:29 +02:00
Théo DELRIEU cea39dfaa8 fix #600
Instead of calling CompatibleObjectType iterator-range constructor,
first convert json::value_type to CompatibleObjectType::value_type
2017-06-07 10:24:59 +02:00
Théo DELRIEU 85de93ba93 add std::pair<CompatibleStringType, T> support 2017-06-06 13:56:16 +02:00
Théo DELRIEU dbebf8de47 add to_json method for C arrays
If the array can be converted to basic_json::string_t, the overload
in this commit is not chosen.
2017-03-16 15:20:39 +01:00