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

abstract object/array type out so that arbitrary types can be used #209

Closed
wants to merge 1 commit into from

Conversation

nlohmann
Copy link
Owner

This pull request fixes some conflicts from #169, but is basically the work of @erichkeane (thanks for that!). I only fixed a conflict and added documentation.

Changes: The container types object_t and array_t can now be set to any container provided that it is aliased to a type with 2 template arguments (object_t - defaulting to std::map<Key,T>) and 1 argument (array_t - defaulting to std::vector<T>).

As the public API changes in a subtle way, the feature can be added in 2.0.0 at the earliest.

@nlohmann nlohmann added this to the Release 2.0.0 milestone Feb 16, 2016
@erichkeane
Copy link

+1, glad I could help!

@nlohmann
Copy link
Owner Author

There is a conceptual problem: using an incomplete type in an unordered_map (here: using std::unordered_map<std::string, basic_json> within the basic_json class) is undefined behavior and the code does not compile with GCC 5. The issue already occurred before, but it seems that std::map (or at least its implementation in GCC and Clang) is more robust as no hashes are calculated.

Possible solution (http://stackoverflow.com/a/8487164/266378):

The solution here is to have an unordered map to a pointer:

That is, changing std::unordered_map<std::string, basic_json> to std::unordered_map<std::string, std::shared_ptr<basic_json>>.

@nlohmann
Copy link
Owner Author

As noted earlier, there is a conceptual issue that needs to be addressed separately.

@nlohmann nlohmann closed this Apr 10, 2016
@nlohmann nlohmann deleted the erichkeane-unordered_map_2 branch April 10, 2016 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants