Skip to content

custom read/write #1351

Answered by stephenberry
moxxxim asked this question in Q&A
Oct 3, 2024 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

Here is a working example on compiler explorer: https://godbolt.org/z/vE7Efaan9

I implemented the read/write as lambdas, but they could be member functions or std::functions, but this is the fastest approach.

Let me know if you have more questions. I've pasted the code below as well for future reference:

#include "glaze/glaze.hpp"

// Only Inner::Type value should be serialized. And then default value of Inner
// object for serialized Inner::Type value will be created on deserialization.
class Inner {
   public:
    enum class Type {
        Type1,
        Type2,
        Type3,
    };

    Inner() = default;
    Inner(Type aType) : type(aType) {}
    Type GetType() const { return type; }
…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@moxxxim
Comment options

@stephenberry
Comment options

Answer selected by stephenberry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants