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 4 commits into
Conversation
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. |
|
Updated. Replaced |
|
I noticed there's still a failure on GCC 11 in |
|
Hi, just checking in after the CI failures. I understand the issue with |
|
Now that #5161 has merged, a few things:
|
Signed-off-by: Federico Sfriso <federicosfriso05@gmail.com>
Signed-off-by: Federico Sfriso <federicosfriso05@gmail.com>
…l ranges include Signed-off-by: Federico Sfriso <federicosfriso05@gmail.com>
113af6b to
60ecc77
Compare
|
I've rebased and applied all 4 fixes you suggested. Given the |
|
Thanks for rebasing! I asked Claude Code to dig into this locally with g++-12 + libstdc++, which reproduces the failure, and I want to save you some cycles because a couple of the natural fixes don't actually work. The red across the whole gcc/clang matrix isn't your new test — it's Two things I checked with Claude:
The crux is that any specialization keyed on This one's genuinely fiddly template-wise. The key is to build |
Signed-off-by: Federico Sfriso <federicosfriso05@gmail.com>
2ebbab6 to
e11531b
Compare
|
Here's what changed after the last commit:
I replaced After building Is there something I have to change? Happy to follow any your advice. |
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.