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

Document and test std::ranges functionality #1826

Open
lemire opened this issue May 18, 2022 · 0 comments
Open

Document and test std::ranges functionality #1826

lemire opened this issue May 18, 2022 · 0 comments

Comments

@lemire
Copy link
Member

lemire commented May 18, 2022

For C++20 users, we support std::ranges somewhat under the DOM API but it is undocumented.

#include "simdjson.h"
#include <iostream>
#include <ranges>
using namespace simdjson;
int main(void) {
  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;
  dom::parser parser;
  auto justmodel = [](auto car) { return car["model"]; };
  for (auto car : parser.parse(cars_json).get_array() | std::views::transform(justmodel)) {
    std::cout << car << std::endl;
  }
}

Also it would be nice to extend std::ranges to ondemand.

@lemire lemire added this to the 2.0 milestone May 18, 2022
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

No branches or pull requests

1 participant