Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glz::meta not supported for enum flags? #1567

Open
powerof3 opened this issue Jan 14, 2025 · 0 comments
Open

glz::meta not supported for enum flags? #1567

powerof3 opened this issue Jan 14, 2025 · 0 comments

Comments

@powerof3
Copy link

#include <iostream>
#include "glaze/glaze.hpp"

enum class MyEnum {
    X = 1 << 0, 
    Y = 1 << 1, 
    Z = 1 << 2
};

MyEnum operator|(MyEnum  a, MyEnum  b)
{
    return static_cast<MyEnum>(static_cast<int>(a) | static_cast<int>(b));
}

template<>
struct glz::meta<MyEnum> {
	using enum MyEnum;
	static constexpr auto value = enumerate(X, Y, Z);
};

struct my_struct {

    MyEnum flags{ MyEnum::X | MyEnum::Z };
};

int main() {
    my_struct obj{};

    std::cout << glz::write_json(obj).value_or("error") << '\n';
    return 0;
}

This displays as {"flags":5} instead of the expected string value (eg. {"flags": "X | Z"})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant