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

Serializing class derived from std::variant #166

Open
blear-cadence opened this issue Jun 24, 2024 · 0 comments
Open

Serializing class derived from std::variant #166

blear-cadence opened this issue Jun 24, 2024 · 0 comments

Comments

@blear-cadence
Copy link

Sorry if I missed this, but I checked the discussions and searched the doc, but I can't see how to make this work.

#include "zpp_bits.h"

#include <string>
#include <variant>
#include <vector>

struct s : public std::variant< int, std::string >
{
    bool holds_id() const { return std::holds_alternative< int >( *this ); }
    int  get_id() const { return std::get< int >( *this ); }
    bool holds_name() const
    {
        return std::holds_alternative< std::string >( *this );
    }
    std::string get_name() const { return std::get< std::string >( *this ); }

    using base = std::variant< int, std::string >;
    using base::base;
    using base::operator=;
};

int main()
{
    s an_s;
    an_s = 34;

    std::vector< char > v;
    zpp::bits::out      out{ v };
    auto                result = out( an_s );

    if ( failure( result ) )
    {
        return 1;
    }
    return 0;
}
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