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

ordered_json doesn't support range based erase #3108

Closed
jgannon65 opened this issue Oct 28, 2021 · 3 comments · Fixed by #3109
Closed

ordered_json doesn't support range based erase #3108

jgannon65 opened this issue Oct 28, 2021 · 3 comments · Fixed by #3109
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

@jgannon65
Copy link

ordered_json uses ordered_map and ordered_map lacks a range based(iterator pair) erase method. This means that it's not possible to use algorithms like std::unique, std::remove_if etc on an ordered_json, even if you're trying to use it on a json array, bc it will not compile.

@nlohmann
Copy link
Owner

I can confirm this:

#include <iostream>
#include <nlohmann/json.hpp>
#include <algorithm>

using json = nlohmann::json;
using ordered_json = nlohmann::ordered_json;

int main() {
    json j = {1,2,2,4};
    //ordered_json j = {1,2,2,4}; // does not compile

    auto last = std::unique(j.begin(), j.end());
    j.erase(last, j.end());

    std::cout << j << std::endl;
}

This compiles with json, but not with ordered_json.

@nlohmann nlohmann self-assigned this Oct 30, 2021
@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Oct 30, 2021
@nlohmann
Copy link
Owner

Feedback on #3109 greatly appreciated!

@nlohmann nlohmann added the state: help needed the issue needs help to proceed label Oct 30, 2021
@nlohmann
Copy link
Owner

Help needed with #3109, see #3109 (comment).

@nlohmann nlohmann added this to the Release 3.10.5 milestone Nov 9, 2021
@nlohmann nlohmann added release item: 🐛 bug fix and removed state: help needed the issue needs help to proceed labels Nov 9, 2021
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