Skip to content

How can I get a list with the indices of my key-value array? #1474

Answered by BillyDonahue
dabl03 asked this question in Q&A
Discussion options

You must be logged in to vote

Value has member functions to get you a list of keys. Value is also a C++ range, having begin and end member functions.

I think the library already does what you want. You just have to say it in C++ and not JS.

Value arr{
  {"world_1",{...}},
  {"world_2",{...}},
  ...
};

for (auto&& [k,v] : arr) {
  std::cout
    << "  " << k << ": "
    << v << std::endl;
}

this is very idiomatic C++ container iteration. I think you have to come with some level of experience to use the library. This could be making life a little harder for people don't have or need that basic familiarity to interpret the existing robo-docs.

There could be very basic examples like this added to the README.md or something.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dabl03
Comment options

Answer selected by dabl03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants