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

Allowing users to write directly to std::optional<std::string> #2078

Merged
merged 6 commits into from Oct 28, 2023

Conversation

lemire
Copy link
Member

@lemire lemire commented Oct 27, 2023

  auto json = R"({ "foo1": "3.1416" } )"_padded;
  ondemand::parser parser;
  ondemand::document doc = parser.iterate(json);
  std::optional<std::string> value;
  if(doc["foo1"].get_string(value)) { /* error */ }

@lemire lemire requested a review from anonrig October 27, 2023 20:48
@anonrig
Copy link
Contributor

anonrig commented Oct 27, 2023

Does it make sense to add std::optionalstd::string_view support as well?

@lemire
Copy link
Member Author

lemire commented Oct 27, 2023

Does it make sense to add std::optional<std::string_view> support as well?

With my latest commits, it would, but an std::string_view does not own its content. In simdjson, it can point at the original JSON, or at a buffer hidden inside the parser instance. In the cases that we care about, it is going to live inside the parser instance I think. So you have to be mindful of the lifespan of the data. That is, you should keep both the std::optional<std::string_view> and the parser instances alive.

@lemire lemire merged commit baa7d96 into master Oct 28, 2023
63 of 64 checks passed
@lemire lemire deleted the allowing_std_optional branch October 28, 2023 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants