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

[FEATURE]: C++: add equality operators to classes #2585

Open
beku-epitome opened this issue Apr 29, 2024 · 0 comments
Open

[FEATURE]: C++: add equality operators to classes #2585

beku-epitome opened this issue Apr 29, 2024 · 0 comments
Labels

Comments

@beku-epitome
Copy link
Contributor

Currently the C++ output of quicktype is asymmetrical: boolean, integer, string and array1 types are comparable for equality, but the classes generated for JSON objects aren't. Equality comparison is important to detect if a message's contents are different from a previous one.

Context (Input, Language)

Output Language: C++

Current Behaviour / Output

    struct Payload {
        std::optional<bool> aFlag;
        std::vector<int64_t> indices;
        std::string description;
    };

Proposed Behaviour / Output

Add equality operators to each class (or struct, depending on the configuration), the equality should simply compare each member and perform logical AND on their results:

    struct Payload {
        std::optional<bool> flag;
        std::vector<int64_t> indices;
        std::string name;

        bool operator==(const Payload & other) const {
            return (flag == other.flag) && (indices == other.indices) && (name == other.name);
        }
        bool operator!=(const Payload & other) const {
            return !(*this == other);
        }
    };

Footnotes

  1. if the contained type is also comparable

@inferrinizzard inferrinizzard added the C++ C++ Output label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants