felixguendling / cista

Cista is a simple, high-performance, zero-copy C++ serialization & reflection library.
https://cista.rocks
MIT License
1.8k stars 116 forks source link

hash_storage equality operator doesn't compare values #214

Closed opera-aberglund closed 5 months ago

opera-aberglund commented 5 months ago

I noticed the implementation for the equality operator for the hash_storage only compares the keys, but not the values of the maps. Is there any reason for this?

Current:

bool operator==(hash_storage const& b) const noexcept
    {
        if (size() != b.size()) {
            return false;
        }
        for (auto const& el : *this) {
            if (b.find(GetKey()(el)) == b.end()) {
                return false;
            }
        }
        return true;
    }

Suggested change:

auto it = b.find(GetKey()(el));
if (it == b.end() || GetValue()(el) != it->second) {
    return false;
}
felixguendling commented 5 months ago

Makes sense. Can you please create a PR?