Skip to content

Add document and tests of std::ranges support of DOM API#2381

Merged
lemire merged 3 commits intosimdjson:masterfrom
Cuda-Chen:ranges-dom-doc
Jun 24, 2025
Merged

Add document and tests of std::ranges support of DOM API#2381
lemire merged 3 commits intosimdjson:masterfrom
Cuda-Chen:ranges-dom-doc

Conversation

@Cuda-Chen
Copy link
Contributor

Add document and tests of std::ranges support of DOM API.

Mention #1826.

@Cuda-Chen Cuda-Chen force-pushed the ranges-dom-doc branch 3 times, most recently from 0c79baa to d388ff9 Compare June 23, 2025 07:26
@Cuda-Chen Cuda-Chen marked this pull request as ready for review June 23, 2025 07:39
@lemire
Copy link
Member

lemire commented Jun 23, 2025

@Cuda-Chen Great work. What about code that looks like this...

  auto cars_json = R"( [
   { "make": "Toyota", "model": "Camry",  "year": 2018, "tire_pressure": [ 40.1, 39.9, 37.7, 40.4 ] },
   { "make": "Kia",    "model": "Soul",   "year": 2012, "tire_pressure": [ 30.1, 31.0, 28.6, 28.7 ] },
   { "make": "Toyota", "model": "Tercel", "year": 1999, "tire_pressure": [ 29.8, 30.0, 30.2, 30.5 ] }
 ] )"_padded;
  simdjson::dom::parser parser;
  auto cars = parser.parse(cars_json).get_array() |
              std::views::transform([](auto car) -> std::string_view {
                return car["model"].get_string();
              });

  return std::ranges::equal(
             cars, std::vector<std::string_view>{"Camry", "Soul", "Tercel"})
             ? EXIT_SUCCESS
             : EXIT_FAILURE;

Note that you do not need the value_unsafe() in your code, the cast to std::string_view should be automated and lead to an exception in case of parsing error.

@Cuda-Chen
Copy link
Contributor Author

Hi @lemire ,

What about code that looks like this...
(code block here)

I think this solution appears more acceptable, and I will adopt this one.

@lemire lemire merged commit 7d86b04 into simdjson:master Jun 24, 2025
71 of 75 checks passed
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.

2 participants