Skip to content

Bug: Preserve Insertion Order #18

@ax3l

Description

@ax3l

We want to support preserving insertion order for user friendliness. The current implementation in pals-cpp does not support this, but C++ and even your dependent library has that feature.

Suggestion by Claude:

yaml-cpp does preserve insertion order for mappings. Internally, YAML::Node of type Map stores key-value pairs in a std::vector-like structure (not a std::map), so iteration order matches the order in which keys were inserted or parsed. If you're seeing reordered output, it's likely due to something else in your pipeline rather than yaml-cpp itself.

That said, yaml-cpp has some well-known pain points that might lead you to look for alternatives: it can be slow, has a somewhat heavy API with reference-counted nodes that cause surprising aliasing behavior, and has had periods of infrequent maintenance.

Alternatives

Here are some C++ YAML libraries worth considering depending on your needs:

  • rapidyaml (ryml) — This is generally the top recommendation. It's dramatically faster than yaml-cpp (often 10–50×), has a parse-in-place design similar in spirit to RapidJSON, preserves insertion order, and supports both read and write. It can also round-trip comments in some cases. The API is lower-level than yaml-cpp but very capable.

  • libfyaml — A C library (usable from C++) that is fully YAML 1.2 compliant, fast, and preserves ordering. It also supports round-tripping with comment and whitespace preservation, which is rare. Good choice if you need strict spec compliance.

  • there are more libs, this is just a list of examples

If performance or round-trip fidelity (preserving comments, formatting) matters to you, rapidyaml is probably the strongest choice in the C++ ecosystem. If strict YAML 1.2 compliance is important, libfyaml is worth a look.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions