-
-
Save julian-klode/c9a127170601b95faac6ebf78356c43a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using uint16_t = unsigned short; | |
using uint64_t = unsigned long long; | |
static_assert(sizeof(uint16_t) == 2); | |
static_assert(sizeof(uint64_t) == 8); | |
struct priority { | |
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ | |
uint16_t padding; | |
uint16_t dynamic; | |
uint16_t staticp; | |
uint16_t index; | |
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ | |
uint16_t index; | |
uint16_t staticp; | |
uint16_t dynamic; | |
uint16_t padding; | |
#endif | |
bool operator<(const priority &other) const; | |
private: | |
uint64_t tie() const | |
{ | |
return uint64_t(index) << 48 | uint64_t(staticp) << 32 | uint64_t(dynamic) << 16 | uint64_t(padding); | |
} | |
}; | |
bool priority::operator<(const priority &other) const | |
{ | |
return tie() < other.tie(); | |
// This is not optimized: | |
// return std::tie(index, staticp, dynamic, padding) < std::tie(other.index, other.staticp, other.dynamic, other.padding); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment