Giter VIP home page Giter VIP logo

Comments (7)

stephenberry avatar stephenberry commented on May 27, 2024 1

Agreed, I think glaze_reflect = true should override.

from glaze.

justend29 avatar justend29 commented on May 27, 2024

As a note, many cases may want the enum serialized as integers. Supporting that is worthwhile.

from glaze.

stephenberry avatar stephenberry commented on May 27, 2024

I agree, the default behavior should still be integers.

I think reflection should happen if a glz::meta simply exists for the type:

enum class Color { Red, Green, Blue };

template <>
struct glz::meta<Color> {}; // This definition should trigger enum reflection

from glaze.

justend29 avatar justend29 commented on May 27, 2024

What are your thoughts on making it such that reflect = true must be in the struct to trigger reflection? It seems more explicit to me.

Then, as usual, the standard value = enumerate(...) would override.

from glaze.

stephenberry avatar stephenberry commented on May 27, 2024

Yeah, I think this is probably better for consistency, and then you can flip the reflect flag programmatically if you want:

template <>
struct glz::meta<Color> {
   static constexpr auto reflect = true;
};

from glaze.

justend29 avatar justend29 commented on May 27, 2024

Ouu, yes, flipping would be nice.
So, what would happen here?

template <>
struct glz::meta<Color> {
   static constexpr bool reflect = true;
   static constexpr auto value = enumerate(...);
};

I would think precedence would be as follows, meaning the above would autoreflect, regardless of value.

  1. reflect == true -> auto reflect regardless of value (could instead produce an error if value is also present?)
  2. no reflect and has enumerate value member -> use enumerate value
  3. explicit reflect == true -> attempt to use value member, error on it missing

from glaze.

stephenberry avatar stephenberry commented on May 27, 2024

After thinking about this more, I think it is best to not add pure enum reflection until supported by C++26 (hopefully).

Tagged enum values make this more complex. And, it bifurcates enum handling logic.

It isn't hard to add a using enum statement and just copy the enum list into a glz::meta.

glz::meta also supports renaming enum values.

As cool as enum reflection would be, we don't want pure reflection as the default (integers are default). So, any additional reflection approach would be deprecated in the future. I'm less eager to add features that I know will have deprecated APIs.

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.