Skip to content

Commit

Permalink
Avoid <=> operator because it is not supported on all our targets
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer authored and Swiftb0y committed Sep 6, 2023
1 parent 50318bd commit ded4252
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions src/soundio/soundmanagerutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QList>
#include <QString>
#include <QtDebug>
#include <compare>

#include "util/compatibility/qhash.h"
#include "util/fifo.h"
Expand Down Expand Up @@ -104,7 +103,7 @@ class AudioPath {
}

// CppCoreGuidelines C.161: Use non-member functions for symmetric operators
friend constexpr std::weak_ordering operator<=>(const AudioPath& lhs,
friend constexpr bool operator<(const AudioPath& lhs,
const AudioPath& rhs) noexcept;
friend constexpr bool operator==(const AudioPath& lhs,
const AudioPath& rhs) noexcept;
Expand All @@ -116,30 +115,15 @@ class AudioPath {
unsigned char m_index;
};

constexpr std::weak_ordering operator<=>(const AudioPath& lhs,
// TODO: turn this into operator<=> once all targets fully support that
// XCode 14 probably and GCC 10
constexpr bool operator<(const AudioPath& lhs,
const AudioPath& rhs) noexcept {
// Exclude m_channelGroup from comparison!
// See also: hashValue()/qHash()
// TODO: Why??

// TODO: remove this ifdef when AppleClang ships a libc++
// implementation with operator<=> for tuples (XCode 14 probably)
#ifdef __APPLE__
if (lhs.m_type < rhs.m_type) {
return std::weak_ordering::less;
} else if (lhs.m_type > rhs.m_type) {
return std::weak_ordering::greater;
} else if (lhs.m_index < rhs.m_index) {
return std::weak_ordering::less;
} else if (lhs.m_index > rhs.m_index) {
return std::weak_ordering::greater;
} else {
return std::weak_ordering::equivalent;
}
#else
return std::tie(lhs.m_type, lhs.m_index) <=>
return std::tie(lhs.m_type, lhs.m_index) <
std::tie(rhs.m_type, rhs.m_index);
#endif
}

constexpr bool operator==(const AudioPath& lhs,
Expand Down

0 comments on commit ded4252

Please sign in to comment.