For those who know Python, the best way to explain what I want is by analogy:
[1, [2, 3], 4, [5, [6]], 7]
Obviously, I can implement my own class (template) to do this, but if the standard library has already invented this wheel, I want to avoid re-inventing it (or at least, avoid putting my half-baked re-invented version in my project).
Under the hood, a python list is a dynamically reallocating array, i.e. the same sort of thing as a std::vector
, and its elements are dynamic, i.e. the same sort of thing as std::any
. So the most direct analogue of this code would be
using p = std::vector<std::any>;
auto myList = p { 1, p { 2, 3 }, 4, p { 5, p { 6 } }, 7};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With