Skip to content

Commit

Permalink
breaking: updated dpp::role comparison operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandserver committed Nov 13, 2024
1 parent b0c53bc commit 5e557b0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
17 changes: 2 additions & 15 deletions include/dpp/role.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,8 @@ class DPP_EXPORT role : public managed, public json_interface<role> {
* @param lhs first role to compare
* @param rhs second role to compare
* @return true if lhs is less than rhs
*
* @throws std::invalid_argument when roles of two different guilds are passed
*/
friend inline bool operator< (const role& lhs, const role& rhs) {
if (lhs.guild_id != rhs.guild_id) {
throw std::invalid_argument("cannot compare roles from two different guilds");
}

// the @everyone role is always the lowest role in hierarchy
if (lhs.id == lhs.guild_id) {
return rhs.id != lhs.guild_id;
}

if (lhs.position == rhs.position) {
// the higher the IDs are, the lower the position
return lhs.id > rhs.id;
Expand All @@ -351,8 +340,6 @@ class DPP_EXPORT role : public managed, public json_interface<role> {
* @param lhs first role to compare
* @param rhs second role to compare
* @return true if lhs is greater than rhs
*
* @throws std::invalid_argument when roles of two different guilds are passed
*/
friend inline bool operator> (const role& lhs, const role& rhs) {
return !(lhs < rhs);
Expand All @@ -365,7 +352,7 @@ class DPP_EXPORT role : public managed, public json_interface<role> {
* @return true if is equal to other
*/
inline bool operator== (const role& other) const {
return this->position == other.position;
return this->id == other.id;
}

/**
Expand All @@ -375,7 +362,7 @@ class DPP_EXPORT role : public managed, public json_interface<role> {
* @return true if is not equal to other
*/
inline bool operator!= (const role& other) const {
return this->position != other.position;
return this->id != other.id;
}

/**
Expand Down
13 changes: 2 additions & 11 deletions src/unittest/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,23 +345,14 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b
{
set_test(ROLE_COMPARE, false);
dpp::role role_1, role_2;
role_1.id = 99;
role_1.position = 1;
role_1.guild_id = 123;
role_1.id = 98;
role_2.position = 2;
role_2.guild_id = 123;
set_test(ROLE_COMPARE, role_1 < role_2 && !(role_1 > role_2) && role_1 != role_2);
}
{
set_test(ROLE_COMPARE_CONSIDERING_EVERYONE_ROLE, false);
dpp::role role_1, role_2;
role_1.id = 123;
role_1.position = 2;
role_1.guild_id = 123;
role_2.id = 124;
role_2.position = 2;
role_2.guild_id = 123;
set_test(ROLE_COMPARE_CONSIDERING_EVERYONE_ROLE, role_1 < role_2 && !(role_1 > role_2));
}
{
set_test(ROLE_COMPARE_CONSIDERING_ID, false);
dpp::role role_1, role_2;
Expand Down
1 change: 0 additions & 1 deletion src/unittest/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ DPP_TEST(UTILITY_CDN_ENDPOINT_URL_HASH, "utility::cdn_endpoint_url_hash", tf_off
DPP_TEST(STICKER_GET_URL, "sticker::get_url aka utility::cdn_endpoint_url_sticker", tf_offline);
DPP_TEST(EMOJI_GET_URL, "emoji::get_url", tf_offline);
DPP_TEST(ROLE_COMPARE, "role::operator<", tf_offline);
DPP_TEST(ROLE_COMPARE_CONSIDERING_EVERYONE_ROLE, "role::operator<", tf_offline);
DPP_TEST(ROLE_COMPARE_CONSIDERING_ID, "role::operator<", tf_offline);
DPP_TEST(ROLE_CREATE, "cluster::role_create", tf_online);
DPP_TEST(ROLE_EDIT, "cluster::role_edit", tf_online);
Expand Down

0 comments on commit 5e557b0

Please sign in to comment.