quicktype icon indicating copy to clipboard operation
quicktype copied to clipboard

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

Open beku-epitome opened this issue 1 year ago • 0 comments

Currently the C++ output of quicktype is asymmetrical: boolean, integer, string and array[^1] 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.

[^1]: if the contained type is also comparable

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);
        }
    };

beku-epitome avatar Apr 29 '24 08:04 beku-epitome