-
Notifications
You must be signed in to change notification settings - Fork 162
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
Preserving order for tables #71
Comments
Thank you for the suggestion and information. You are right, the current implementation does not preserve the order of the keys while serialization. In the last few months, I was working on the next major update. Although I didn't think about the key-order problem, the next major release will include custom container support in the similar (a bit different, but essentially the same) way as you mentioned. The main reason why I changed the definition of Now it is still a beta release and has not been merged into master yet, but you can try it. It already passes the same tests that are applied to the current version, but I plan to merge it after I try it with some of my own tools because it includes breaking changes. |
Sorry for the late reply. After v3, you can specify STL-like containers that would be used in const auto data = toml::parse<
toml::preserve_comments, std::map, std::deque
>("example.toml"); For more detail, please see here. |
Thanks for the updates! I just check out version 3. It works great with
With that, it preserves the insertion order, which is nice if you want to write back or output in the initial order from the config file. |
Is there a way to control the order of how elements in a table are serialized? From the readme it seems the tables are implemented as unorderd_map, so I guess that currently results in a (more or less) random order.
For example, it would be nice to optionally have the output preserve the order of the how keys are entered into the table.
For example in https://github.com/nlohmann/json this is realized by providing a template argument that specifies the type used internally to store the table, where one can specify a map data structure that preserves order, see nlohmann/json#546 (comment) and nlohmann/json#485 (comment)
The text was updated successfully, but these errors were encountered: