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

Add a way to get a key reference from the iterator #1127

Closed
GTValentine opened this issue Jun 11, 2018 · 2 comments
Closed

Add a way to get a key reference from the iterator #1127

GTValentine opened this issue Jun 11, 2018 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@GTValentine
Copy link

GTValentine commented Jun 11, 2018

I may be missing something but I think when I am iterating over all keys in an object I have no way to access they key without actually copying them:

bool foo(const std::string&)
{
...
}

json j = {...};
for (auto it = j.begin(); it != j.end(); ++it)
{
	//it.key() copies the entire std::string
	if(foo(it.key()))
	{
		bar(it.value());
	}
}

If my keys are large strings, I'd like to avoid copying them for perf reasons.

@nlohmann
Copy link
Owner

Since #1098, you can access keys by reference. Note this has not been released yet.

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Jun 11, 2018
@GTValentine
Copy link
Author

Oh cool. Can't wait to have it in master.

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

2 participants