Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get all keys of one object? #1177

Closed
oyoungs opened this issue Jul 30, 2018 · 5 comments
Closed

How to get all keys of one object? #1177

oyoungs opened this issue Jul 30, 2018 · 5 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@oyoungs
Copy link

oyoungs commented Jul 30, 2018

Sometimes, I got an object, and need all keys of the object, but the iterator can only give me the value of one key-value pair. I want to use it like "auto keys = obj.keys()" to get all keys, but I can't find the interface. Is there anything to fix?

@oyoungs oyoungs closed this as completed Jul 30, 2018
@oyoungs oyoungs reopened this Jul 30, 2018
@nlohmann
Copy link
Owner

There is no such member function - the same as there is no such function for a std::map. But you can easily create such a function on your own: https://stackoverflow.com/questions/110157/how-to-retrieve-all-keys-or-values-from-a-stdmap-and-put-them-into-a-vector

Related: #1107 #459

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Aug 1, 2018
@nlohmann
Copy link
Owner

nlohmann commented Aug 1, 2018

@GitOyoung Do you need further assistance?

@oyoungs
Copy link
Author

oyoungs commented Aug 21, 2018

Thanks, I try to use the iterator to create a util function, and it works.

@boytjmjler
Copy link

I feel necessary!

@boytjmjler
Copy link

std::string object::key() {
return std::string("key");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants