3 ms·
Technique: Recursive Variants and Boxes
- pharmakom 4y agoWoah Incidental complexity overload. Variants should be first class in C++.
- nly 4y agoBit sad that Boosts recursive variant isn't mentioned. It has been around for ages and makes this kind of thing a lot easier: #include <boost/variant/recursive_variant.hpp> using Document = boost::make_recursive_variant< std::string, int64_t, bool, std::vector<boost::recursive_variant_>, std::map<std::string, boost::recursive_variant_> >::type; Document d; d = std::map<std::string, Document> { {"name", "John"}, {"age", 36}, {"admin", true}, {"hobbies", std::vector<Document> {"programming", "karate"}} };
- kthielen 4y agoIt’s useful, but overspecialized for general use. There are common use-cases for recursive arrays and functions, for example.
- nly 4y agoI have no idea what you mean by this.
- kthielen 4y agoI have no idea why you're confused. :D Does the concept of a recursive array make sense to you? A recursive(ly typed) function? Or do you think such things can't exist? Like "[[[], []], []]" could be an instance of "mu X.[X]" right? https://en.wikipedia.org/wiki/Recursive_data_type#Isorecursive_types https://en.wikipedia.org/wiki/Recursive_data_type#Isorecursi...