Fix ambiguous overloaded operator== in C++20
Polymorphic comparison operators doesn't work in C++20. (-Wambiguous-reversed-operator) Fix this issue by using the non-virtual interface pattern. Bug: chromium:1284275 Change-Id: I79e2bbcd3ae2f3b089183146f7e7c775c493e3f4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/276560 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Daniel.L (Byoungchan) Lee <daniel.l@hpcnt.com> Cr-Commit-Position: refs/heads/main@{#38210}
This commit is contained in:
parent
31c373b865
commit
8c4601b831
@ -258,7 +258,9 @@ class RTCStatsMemberInterface {
|
||||
virtual std::vector<NonStandardGroupId> group_ids() const { return {}; }
|
||||
// Type and value comparator. The names are not compared. These operators are
|
||||
// exposed for testing.
|
||||
virtual bool operator==(const RTCStatsMemberInterface& other) const = 0;
|
||||
bool operator==(const RTCStatsMemberInterface& other) const {
|
||||
return IsEqual(other);
|
||||
}
|
||||
bool operator!=(const RTCStatsMemberInterface& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
@ -280,6 +282,8 @@ class RTCStatsMemberInterface {
|
||||
RTCStatsMemberInterface(const char* name, bool is_defined)
|
||||
: name_(name), is_defined_(is_defined) {}
|
||||
|
||||
virtual bool IsEqual(const RTCStatsMemberInterface& other) const = 0;
|
||||
|
||||
const char* const name_;
|
||||
bool is_defined_;
|
||||
};
|
||||
@ -309,17 +313,6 @@ class RTCStatsMember : public RTCStatsMemberInterface {
|
||||
bool is_sequence() const override;
|
||||
bool is_string() const override;
|
||||
bool is_standardized() const override { return true; }
|
||||
bool operator==(const RTCStatsMemberInterface& other) const override {
|
||||
if (type() != other.type() || is_standardized() != other.is_standardized())
|
||||
return false;
|
||||
const RTCStatsMember<T>& other_t =
|
||||
static_cast<const RTCStatsMember<T>&>(other);
|
||||
if (!is_defined_)
|
||||
return !other_t.is_defined();
|
||||
if (!other.is_defined())
|
||||
return false;
|
||||
return value_ == other_t.value_;
|
||||
}
|
||||
std::string ValueToString() const override;
|
||||
std::string ValueToJson() const override;
|
||||
|
||||
@ -363,6 +356,19 @@ class RTCStatsMember : public RTCStatsMemberInterface {
|
||||
return &value_;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool IsEqual(const RTCStatsMemberInterface& other) const override {
|
||||
if (type() != other.type() || is_standardized() != other.is_standardized())
|
||||
return false;
|
||||
const RTCStatsMember<T>& other_t =
|
||||
static_cast<const RTCStatsMember<T>&>(other);
|
||||
if (!is_defined_)
|
||||
return !other_t.is_defined();
|
||||
if (!other.is_defined())
|
||||
return false;
|
||||
return value_ == other_t.value_;
|
||||
}
|
||||
|
||||
private:
|
||||
T value_;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user