-
Notifications
You must be signed in to change notification settings - Fork 98
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
Separate concepts for reading and writing containers #319
Comments
Have you looked at the new From the README: Sometimes you just want to write out JSON structures on the fly as efficiently as possible. Glaze provides tuple-like structures that allow you to stack allocate structures to write out JSON with high speed. These structures are named glz::obj for objects and glz::arr for arrays. Below is an example of building an object, which also contains an array, and writing it out. auto obj = glz::obj{"pi", 3.14, "happy", true, "name", "Stephen", "arr", glz::arr{"Hello", "World", 2}};
std::string s{};
glz::write_json(obj, s);
expect(s == R"({"pi":3.14,"happy":true,"name":"Stephen","arr":["Hello","World",2]})"); |
Thanks for the feedback. I am aware of these new logging structures, but my example really was contrived. What I was trying to illustrate is there's some arbitrary input/forward range that needs to be written. In my use case, this input range isn't actually static and needs to be transformed into a different format for serialization. An example more apt may be: glz::write_json(gather_outside_information() | std::views::transform(information_to_pair)) Separating my use case from these concepts, though, I do believe it's more accurate to divide glaze's concepts into those for reading and those for writing, as the requirements are different, and there's no need to require what's not used. I see that you feel there's a benefit here. If I'm understanding everything correctly, and correct me if I'm not, it's worthwhile to separate the concepts for reading from writing containers. Does a naming system like |
Thanks for The additional information. I think it makes sense to separate concepts for write and read, |
This call seems to avoid the Is my interpretation of this correct? Is that desired? |
* add cmake preset file for simpler build+test * save unchanged common.hpp - clang-format changes * attempt to separate write from read of mapt_t * use result of [[nodiscard]] function in test; avoid warning * gracefully fail testing variant to avoid subproc aborted * fix variant auto-deducible func w/ split maps * rm 'value_type' nested type alias requirement for ranges * refactor to_json(map) for in ranges + first el mistreatment * require 'range' concept to be input range * use free functions that are compat. w/ more types * create some tests for writing map-like ranges * add basic writing in input ranges as arrays * replace ranges::empty() w/ internal alternative for older compilers * disable tests w/ views when views unavailable * fix circular include * fix MSVC literal issue * use glz::sv instead of literal sv * attempt MSVC fix removing operator"" * serialize pair as object * correct expected json in write pair test * provide reading specialization for pair * uncomment "issue". UT can run, there's just no default printing for maps * test reading pairs * read binary pair specialization * refactor json tests to avoid expected. glz::expected subset of std::expected * provide deduction guides on test-case structs for apple-clang * classify pair_t as object when auto-deducing variant * document breaking std::pair change * Version 1.3.0 bump --------- Co-authored-by: Stephen Berry <stephenberry.developer@gmail.com>
Completed: PR |
Although the use of concepts throughout Glaze is marvellous, I've run into a problem where they're overly restrictive.
For example, the
map_t
concept is applied to the default map reading and map writing. Thismap_t
concept requiresmap_subscriptable
, but this seems to only be required for reading, not writing.I would like to instead offer separate concepts for maps, and the other types, that are specific to reading or writing. This will allow writing forward ranges, which don't have direct access, like
map_subscriptable
.Slightly contrived example:
I'm happy to contribute these changes, with tests of course, but would first like to get feedback to see if I'm misinterpreting anything and get your general feelings about these changes before they are made. I also don't have the time to complete this immediately, so it might be a bit.
The text was updated successfully, but these errors were encountered: