Giter Club home page Giter Club logo

Comments (2)

llchan avatar llchan commented on August 27, 2024

Found a workaround for now:

template <>
struct glz::meta<Foo>
{
    static constexpr auto custom_write = true;
    static constexpr auto value = enumerate(Foo::eABC);
};

This basically tricks glaze into treating Foo as a glaze_enum_t which goes into the string-ish branch of write_pair_content. I should mention that in my actual use case for this, the enum comes from a third party lib and has hundreds of values and the enum to string function is not constexpr, so using the enumerate_no_reflect function on its own will not work. It's sufficient to just do a enumerate() with a single enum value which is enough to get glaze to treat it like an enum.

from glaze.

stephenberry avatar stephenberry commented on August 27, 2024

Another solution for your original code is to use the .raw option in glz::opts when writing. The .raw option writes out string-like values without quotes.

This line: write<json>::op<Opts>(fooName(foo), args...);
becomes:
write<json>::op<opt_true<Opts, &opts::raw>>(fooName(foo), args...);

glz::opt_true is used as a helper for setting the appropriate boolean at compile time of the templated options, so that the rest of the options get properly passed through.

Here's a working example on compiler explorer of your code: https://gcc.godbolt.org/z/jsf6W57oa

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.