getml / reflect-cpp

A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]
https://getml.github.io/reflect-cpp/
MIT License
901 stars 76 forks source link

Add compile-time regex support using Hanickadot's CTRE #37

Closed ChemiCalChems closed 8 months ago

ChemiCalChems commented 8 months ago

It would be nice to add support for compile-time regular expressions for the following reasons as it would

This last point seems like science-fiction, or like something that wouldn't ever be useful, but with the addition of #embed to C23 and its likely addition to C++ at some point (hopefully by C++26) it wouldn't be crazy to expect users to want to configure programs using inline / embedded JSON or other formats. There are already a few options for compile-time JSON parsing, so it's not unheard of, in which case, validation of JSON fields would be necessary too.

For all this, I propose (and will be working on a PR for) the addition of Hanickadot's CTRE as a dependency, as well as tweaks in the validator code to get rid of the extremely slow std::regex. If you want to see the speed differences, please check P1433R0, which received a very positive reaction from the C++ Standard's committee (hopefully we'll have a constexpr capable option for regex in the standard library soon).

liuzicheng1987 commented 8 months ago

@ChemiCalChems Looking forward to it!

liuzicheng1987 commented 8 months ago

@ChemiCalChems when you add the library as a dependency, please just copy over the header and mention that in the README, just like YYJSON.

This is part of the core functionality and should work out-of-the-box.

ChemiCalChems commented 8 months ago

@liuzicheng1987 I was thinking of adding the library in as a git submodule for better trackability in versioning and updating in the future. It would also help (in the case adding YYJSON as a submodule too) our repo not be listed as mostly C just because of dependencies. Github also has tracking for submodules, listing them as a link to the repo they originally mirror, which is nice. The only problem is adding a whole submodule for a single header file. I've read up on git sparse-checkout but that seems to be a local-only solution, which sucks...

Another idea I had was having whatever submodules we want in a submodule directory and then symlinking whatever directories we do need wherever they happen to be needed. Maybe we could discuss this at some point.

liuzicheng1987 commented 8 months ago

@ChemiCalChems , thank you for your PR. I have merged it and we can now close this issue.