What if this library was built around std::variant
?
#4100
Ericson2314
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
We target C++11. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I get that major rewrites could well just be out of the question, but this nags at me from time to time so I figured I'd at least write it down?
What if this library was built around
std::variant
. Perhaps this would be evenstd::variant<nullptr_t, someNumberType, std::string, std::vector<json>, std::map<std::string, json>>
, or perhaps it would be something with more json-specific variant types.The big advantage would be that we would be able to leverage
std::variant
downcasting/visiting, to elide redundant checks and make sure all the cases are handled.Most recently I thought of this when reviewing NixOS/nix#8760 (in a project that uses this library). Note how the new methods added for nice error do not have informative return types that indicate what is checked. That is an example of something we could do better on with
std::variant
without extra copying.Beta Was this translation helpful? Give feedback.
All reactions