Merge pull request #59779 from rainerdeyke/constexpr-operators

Made Key operators constexpr
This commit is contained in:
JFonS 2022-08-23 15:35:35 +02:00 committed by GitHub
commit c7a7aad30d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 20 deletions

View File

@ -329,67 +329,71 @@ enum class KeyModifierMask {
// To avoid having unnecessary operators, only define the ones that are needed.
inline Key operator-(uint32_t a, Key b) {
constexpr Key operator-(uint32_t a, Key b) {
return (Key)(a - (uint32_t)b);
}
inline Key &operator-=(Key &a, int b) {
return (Key &)((int &)a -= b);
constexpr Key &operator-=(Key &a, int b) {
a = static_cast<Key>(static_cast<int>(a) - static_cast<int>(b));
return a;
}
inline Key operator+(Key a, int b) {
constexpr Key operator+(Key a, int b) {
return (Key)((int)a + (int)b);
}
inline Key operator+(Key a, Key b) {
constexpr Key operator+(Key a, Key b) {
return (Key)((int)a + (int)b);
}
inline Key operator-(Key a, Key b) {
constexpr Key operator-(Key a, Key b) {
return (Key)((int)a - (int)b);
}
inline Key operator&(Key a, Key b) {
constexpr Key operator&(Key a, Key b) {
return (Key)((int)a & (int)b);
}
inline Key operator|(Key a, Key b) {
constexpr Key operator|(Key a, Key b) {
return (Key)((int)a | (int)b);
}
inline Key &operator|=(Key &a, Key b) {
return (Key &)((int &)a |= (int)b);
constexpr Key &operator|=(Key &a, Key b) {
a = static_cast<Key>(static_cast<int>(a) | static_cast<int>(b));
return a;
}
inline Key &operator|=(Key &a, KeyModifierMask b) {
return (Key &)((int &)a |= (int)b);
constexpr Key &operator|=(Key &a, KeyModifierMask b) {
a = static_cast<Key>(static_cast<int>(a) | static_cast<int>(b));
return a;
}
inline Key &operator&=(Key &a, KeyModifierMask b) {
return (Key &)((int &)a &= (int)b);
constexpr Key &operator&=(Key &a, KeyModifierMask b) {
a = static_cast<Key>(static_cast<int>(a) & static_cast<int>(b));
return a;
}
inline Key operator|(Key a, KeyModifierMask b) {
constexpr Key operator|(Key a, KeyModifierMask b) {
return (Key)((int)a | (int)b);
}
inline Key operator&(Key a, KeyModifierMask b) {
constexpr Key operator&(Key a, KeyModifierMask b) {
return (Key)((int)a & (int)b);
}
inline Key operator+(KeyModifierMask a, Key b) {
constexpr Key operator+(KeyModifierMask a, Key b) {
return (Key)((int)a + (int)b);
}
inline Key operator|(KeyModifierMask a, Key b) {
constexpr Key operator|(KeyModifierMask a, Key b) {
return (Key)((int)a | (int)b);
}
inline KeyModifierMask operator+(KeyModifierMask a, KeyModifierMask b) {
constexpr KeyModifierMask operator+(KeyModifierMask a, KeyModifierMask b) {
return (KeyModifierMask)((int)a + (int)b);
}
inline KeyModifierMask operator|(KeyModifierMask a, KeyModifierMask b) {
constexpr KeyModifierMask operator|(KeyModifierMask a, KeyModifierMask b) {
return (KeyModifierMask)((int)a | (int)b);
}