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

can't parse std::vector<std::byte> #2869

Closed
Spongman opened this issue Jul 15, 2021 · 7 comments · Fixed by #2550
Closed

can't parse std::vector<std::byte> #2869

Spongman opened this issue Jul 15, 2021 · 7 comments · Fixed by #2550
Assignees
Labels
confirmed kind: bug solution: duplicate the issue is a duplicate; refer to the linked issue instead solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@Spongman
Copy link

this worked in v2.1.1, but no longer works in v3.9.1:

int main() {
	std::vector<std::byte> rg;
	nlohmann::json::parse({rg.begin(), rg.end()});
}
include/nlohmann/nlohmann/json.hpp:5164:40: error: no matching function for call to ‘nlohmann::detail::iterator_input_adapter<const char*>::iterator_input_adapter(nlohmann::detail::iterator_input_adapter_factory<__gnu_cxx::__normal_iterator<std::byte*, std::vector<std::byte> >, void>::adapter_type)’
 5164 |         : ia(input_adapter(first, last)) {}

i tried just passing the iterators directly:

int main() {
	std::vector<std::byte> rg;
	nlohmann::json::parse(rg.begin(), rg.end());
}

but this gives a bunch of these:

include/nlohmann/nlohmann/json.hpp:7423:59: error: cannot convert ‘char’ to ‘std::byte’ in initialization
 7423 |                 std::array<char_type, 4> true_literal = {{'t', 'r', 'u', 'e'}};
      |                                                           ^~~
      |                                                           |
      |                                                           char
@nlohmann
Copy link
Owner

This works on the latest develop branch (I did not check 3.9.1):

#include <iostream>
#include "json.hpp"

using json = nlohmann::json;

int main()
{
    std::vector<std::byte> rg = {(std::byte)'t', (std::byte)'r', (std::byte)'u', (std::byte)'e'};
    auto j = nlohmann::json::parse(rg.begin(), rg.end());
    std::cout << j << std::endl;
}

Output:

true

@nlohmann nlohmann added solution: proposed fix a fix for the issue has been proposed and waits for confirmation and removed kind: bug labels Jul 15, 2021
@Spongman
Copy link
Author

are you going to tag a release containing this fix any time soon? or should i just try to cherry-pick this into 3.9.1?

@nlohmann
Copy link
Owner

It is fixed with #2550 and will be part of the next release. I do not have a release date, though.

@nlohmann
Copy link
Owner

Duplicate of #2546.

@nlohmann nlohmann linked a pull request Jul 15, 2021 that will close this issue
1 task
@nlohmann nlohmann added the solution: duplicate the issue is a duplicate; refer to the linked issue instead label Jul 15, 2021
@nlohmann nlohmann added this to the Release 3.9.2 milestone Jul 15, 2021
@nlohmann nlohmann self-assigned this Jul 15, 2021
@Spongman
Copy link
Author

i see that 3.9.1 was nearly 11 months ago. would it be possible to have separate branches for bug fixes and new features and prioritize releasing fixes to bugs like this?

@nlohmann
Copy link
Owner

No, I'm sorry I don't have the capacity to do so. develop is the bleeding-edge branch, and the next release will be hopefully done soon.

@nlohmann
Copy link
Owner

(I am running this project beside my day job, so I cannot make any promises or guarantees. You can sponsor my work, though.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug solution: duplicate the issue is a duplicate; refer to the linked issue instead 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