Coder Social home page Coder Social logo

Comments (6)

stephenberry avatar stephenberry commented on June 18, 2024

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.

stephenberry avatar stephenberry commented on June 18, 2024

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.

stephenberry avatar stephenberry commented on June 18, 2024

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.

stephenberry avatar stephenberry commented on June 18, 2024

Glad you're finding the library useful. Let me know if you run into any more issues.

from glaze.

kalmjasper avatar kalmjasper commented on June 18, 2024

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.

stephenberry avatar stephenberry commented on June 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.