Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch from json to ordered_json #3343

Closed
gkriger opened this issue Feb 20, 2022 Discussed in #3342 · 2 comments · Fixed by #3370
Closed

switch from json to ordered_json #3343

gkriger opened this issue Feb 20, 2022 Discussed in #3342 · 2 comments · Fixed by #3370
Assignees
Labels
confirmed kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@gkriger
Copy link

gkriger commented Feb 20, 2022

Discussed in #3342

Originally posted by gkriger February 18, 2022
From the perspective of casual user the most natural way of switching the code base to ordered_json seems to be replacing

using json = nlohmann::json;

with

using json = nlohmann::ordered_json; 

And the things mostly work. However, this:

json::object_t jobj({ { "product", "one" } });

does not compile however it compiles just fine with using json = nlohmann::json;
Compiler: Microsoft Visual C++ Compiler 16.4.29609.76 (x86_amd64) with c++11 flag.
lib release version 3.10.5

@nlohmann
Copy link
Owner

I can reproduce the issue with Apple Clang:

In file included from /Users/niels/Code/projects/json-test/cmake-build-debug/_deps/json-src/include/nlohmann/json.hpp:86:
/Users/niels/Code/projects/json-test/cmake-build-debug/_deps/json-src/include/nlohmann/ordered_map.hpp:38:11: error: no matching constructor for initialization of 'std::vector<std::pair<const string, basic_json<nlohmann::ordered_map>>>'
        : Container{init, alloc} {}
          ^        ~~~~~~~~~~~~~
/Users/niels/Code/projects/json-test/main.cpp:8:20: note: in instantiation of member function 'nlohmann::ordered_map<std::string, nlohmann::basic_json<nlohmann::ordered_map>>::ordered_map' requested here
    json::object_t jobj({ { "product", "one" } });
                   ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:560:5: note: candidate constructor not viable: no known conversion from 'std::initializer_list<basic_json<nlohmann::ordered_map>>' to 'const std::vector<std::pair<const std::string, nlohmann::basic_json<nlohmann::ordered_map>>>' for 1st argument
    vector(const vector& __x, const allocator_type& __a);
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:569:5: note: candidate constructor not viable: no known conversion from 'initializer_list<nlohmann::basic_json<nlohmann::ordered_map>>' to 'initializer_list<std::vector<std::pair<const std::string, nlohmann::basic_json<nlohmann::ordered_map>>>::value_type>' for 1st argument
    vector(initializer_list<value_type> __il, const allocator_type& __a);
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:580:5: note: candidate constructor not viable: no known conversion from 'std::initializer_list<basic_json<nlohmann::ordered_map>>' to 'std::vector<std::pair<const std::string, nlohmann::basic_json<nlohmann::ordered_map>>>' for 1st argument
    vector(vector&& __x, const allocator_type& __a);
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:519:5: note: candidate constructor not viable: no known conversion from 'std::initializer_list<basic_json<nlohmann::ordered_map>>' to 'std::vector<std::pair<const std::string, nlohmann::basic_json<nlohmann::ordered_map>>>::size_type' (aka 'unsigned long') for 1st argument
    vector(size_type __n, const value_type& __x);
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:522:9: note: candidate template ignored: substitution failure [with _InputIterator = std::initializer_list<nlohmann::basic_json<nlohmann::ordered_map>>]: no type named 'reference' in 'std::iterator_traits<std::initializer_list<nlohmann::basic_json<nlohmann::ordered_map>>>'
        vector(_InputIterator __first,
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:537:9: note: candidate template ignored: substitution failure [with _ForwardIterator = std::initializer_list<nlohmann::basic_json<nlohmann::ordered_map>>]: no type named 'reference' in 'std::iterator_traits<std::initializer_list<nlohmann::basic_json<nlohmann::ordered_map>>>'
        vector(_ForwardIterator __first,
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:503:40: note: candidate constructor not viable: requires single argument '__a', but 2 arguments were provided
    _LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
                                       ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:515:14: note: candidate constructor not viable: requires single argument '__n', but 2 arguments were provided
    explicit vector(size_type __n);
             ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:559:5: note: candidate constructor not viable: requires single argument '__x', but 2 arguments were provided
    vector(const vector& __x);
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:566:5: note: candidate constructor not viable: requires single argument '__il', but 2 arguments were provided
    vector(initializer_list<value_type> __il);
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:572:5: note: candidate constructor not viable: requires single argument '__x', but 2 arguments were provided
    vector(vector&& __x)
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:520:5: note: candidate constructor not viable: requires 3 arguments, but 2 were provided
    vector(size_type __n, const value_type& __x, const allocator_type& __a);
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:497:5: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
    vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:530:9: note: candidate constructor template not viable: requires at least 3 arguments, but 2 were provided
        vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/include/c++/v1/vector:544:9: note: candidate constructor template not viable: requires at least 3 arguments, but 2 were provided
        vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
        ^
1 error generated.

The issue seems to be a missing constructor in the implementation of ordered_map.

@gkriger
Copy link
Author

gkriger commented Feb 20, 2022

Great. Are you going to address that in the next release? Is 3.10.5 going to be in Ubuntu 22.04LTS or there is a possibility that this will be fixed there? Feature freeze is close.

falbrechtskirchinger added a commit to falbrechtskirchinger/json that referenced this issue Mar 3, 2022
One of the ordered_map constructors was incorrectly accepting a
std::initializer_list<T> instead of std::initializer_list<value_type>.

Add regression test.

Fixes nlohmann#3343.
falbrechtskirchinger added a commit to falbrechtskirchinger/json that referenced this issue Mar 6, 2022
One of the ordered_map constructors was incorrectly accepting a
std::initializer_list<T> instead of std::initializer_list<value_type>.

Add regression test.

Fixes nlohmann#3343.
@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Mar 7, 2022
@nlohmann nlohmann added this to the Release 3.10.6 milestone Mar 7, 2022
@nlohmann nlohmann self-assigned this Mar 7, 2022
nlohmann pushed a commit that referenced this issue Mar 7, 2022
One of the ordered_map constructors was incorrectly accepting a
std::initializer_list<T> instead of std::initializer_list<value_type>.

Add regression test.

Fixes #3343.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants