fix: support constructing json from C++20 range views (#4916)#5205
fix: support constructing json from C++20 range views (#4916)#5205federicosfriso05-dotcom wants to merge 2 commits into
Conversation
Signed-off-by: Federico Sfriso <federicosfriso05@gmail.com>
ee84434 to
7593e0c
Compare
|
Hi, I noticed the Windows/MinGW builds are failing. After investigating the CI logs, the issue seems to be related to an incomplete C++20 ranges implementation in MinGW GCC 12.2.0, where |
|
IIRC we also excluded some other older compilers from other C++20 features. So I guess and ifdef with some specific versions and comments would be sufficient. |
Signed-off-by: Federico Sfriso <federicosfriso05@gmail.com>
|
Updated. Replaced |
|
I noticed there's still a failure on GCC 11 in |
Description
Fixes #4916.
Constructing a
nlohmann::jsonobject from a C++20 range view (e.g.std::views::filter,std::views::transform) failed to compile becauseis_compatible_array_typedid not recognize range views as compatible types.What changed
include/nlohmann/detail/meta/type_traits.hpp: added a new partial specialization ofis_compatible_array_type_implfor C++20 range views, guarded by#ifdef JSON_HAS_CPP_20. The specialization matches types satisfyingstd::ranges::viewwhile excluding character sequences (e.g.std::string_view).include/nlohmann/detail/conversions/to_json.hpp: added a newconstructoverload for C++20 range views insideexternal_constructor<value_t::array>, also guarded by#ifdef JSON_HAS_CPP_20.std::ranges::viewrather than juststd::ranges::rangeto avoid ambiguity with standard containers likestd::stringandstd::string_view, which already satisfystd::ranges::rangebut are handled by existing specializations. Character sequences are additionally excluded by checking that the range's value type is not char or wchar_t.How to test
make amalgamate.