Comments (6)
What you are doing looks correct. From debugging quickly it looks like this is an issue with nested lambda calls in Glaze. The glz::meta
value is invoking a lambda that invokes the FixedName
lambda. This should work, but it appears to be misinterpreting the nested lambda as a nullable. So, yes this is a bug in Glaze. But, it shouldn't be too difficult to fix.
from glaze.
Ah, I discovered this is not a Glaze bug, but rather a bug in your code. Your glz::meta<in_addr>
returns an Rvalue of FixedName<INET_ADDRSTRLEN>
. However, your glaze
definition in FixedName
only accepts Lvalues. If you change [](FixedName& self)
to [](cosnt FixedName& self)
or [](FixedName&& self)
, to either accept a const lvalue or an rvalue then your code will run as desired.
This does bring up the question of whether we can catch these errors at compile time. But, I don't currently see a straightforward solution, because the lambda approach needs to be extremely flexible and support rvalues, lvalues, etc. It can also return nullable types and function pointers, so it's very hard to determine what is appropriate. Eventually we may be able to improve the code to catch these errors, but for now make sure that your functions support rvalues.
from glaze.
I added a test case based on your example to the code with a comment about the challenges of detecting this user error. #996
from glaze.
Glad you're finding the library useful. Let me know if you run into any more issues.
from glaze.
Thanks it's working perfectly now! Makes sense that you can't cast an rvalue in an lvalue.
For my understanding: How does this not result in a compile time bug but rather in a runtime bug? Passing an rvalue to a function that only accepts an lvalue seems like a compile time thing to catch
from glaze.
From my debugging it looks like the lambda is convertible to an lvalue function pointer, so it continually tries to deference and then create a new pointer to the lambda. I think this bug could probably be caught, but it's confusing to debug.
from glaze.
Related Issues (20)
- calculate serialize size before serialization and serialize to pre-allocated memory HOT 4
- Option to use partial with char* or char[] HOT 7
- data_must_be_null_terminated issue HOT 4
- Raw char buffer handling HOT 2
- Built-in support for type control HOT 3
- reflection fails with custom serializer for std::chrono types on clang/gcc HOT 7
- How do I write an enum as a raw string? HOT 1
- compile error with error_on_missing_keys HOT 1
- old GCC 11.4.0 compiler support HOT 8
- Link to NDJSON website looks sus... HOT 2
- [ICE] `msvc 17.8` (`glaze 2.8.1`) HOT 1
- Numeric variant deduction type
- Write_binary/read_binary support for the "json_t" interface HOT 6
- is_[json_type] concepts in glz:: namespace
- Compilation error when structure have more than 32 fields HOT 1
- How to pass glz::read_json to a std::function? HOT 1
- Support std::variant<...,std::variant<...> > HOT 2
- repe::registry needs to handle throws on function calls
- Tuple routines not working as expected HOT 1
- Does glaze handle structs with static members ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from glaze.