Browse Source

update: operator overloading of common code

master
Dnomd343 2 months ago
parent
commit
40fd7856ad
  1. 12
      src/core/common_code/common_code.h
  2. 16
      src/core/common_code/internal/common_code.inl

12
src/core/common_code/common_code.h

@ -139,18 +139,20 @@ public:
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
/// Compare CommonCode with u64 values. /// Compare CommonCode with u64 values.
friend constexpr auto operator==(const CommonCode &c1, uint64_t c2); friend constexpr auto operator==(const CommonCode &lhs, uint64_t rhs);
friend constexpr auto operator<=>(const CommonCode &c1, uint64_t c2); friend constexpr auto operator<=>(const CommonCode &lhs, uint64_t rhs);
/// Compare the original values of two CommonCodes. /// Compare the original values of two CommonCodes.
friend constexpr auto operator==(const CommonCode &c1, const CommonCode &c2); friend constexpr auto operator==(const CommonCode &lhs, const CommonCode &rhs);
friend constexpr auto operator<=>(const CommonCode &c1, const CommonCode &c2); friend constexpr auto operator<=>(const CommonCode &lhs, const CommonCode &rhs);
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
private: private:
uint64_t code_; uint64_t code_;
// ------------------------------------------------------------------------------------- //
/// Serialize CommonCode into a 9-bit length string. /// Serialize CommonCode into a 9-bit length string.
static std::string string_encode(uint64_t common_code); static std::string string_encode(uint64_t common_code);
@ -159,6 +161,8 @@ private:
/// Deserialize CommonCode from string and return std::nullopt on error. /// Deserialize CommonCode from string and return std::nullopt on error.
static std::optional<uint64_t> string_decode(const std::string &common_code); static std::optional<uint64_t> string_decode(const std::string &common_code);
// ------------------------------------------------------------------------------------- //
}; };
} // namespace klotski::codec } // namespace klotski::codec

16
src/core/common_code/internal/common_code.inl

@ -21,20 +21,20 @@ inline std::ostream& operator<<(std::ostream &out, const CommonCode self) {
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
constexpr auto operator==(const CommonCode &c1, const uint64_t c2) { constexpr auto operator==(const CommonCode &lhs, const uint64_t rhs) {
return c1.code_ == c2; return lhs.code_ == rhs;
} }
constexpr auto operator<=>(const CommonCode &c1, const uint64_t c2) { constexpr auto operator<=>(const CommonCode &lhs, const uint64_t rhs) {
return c1.code_ <=> c2; return lhs.code_ <=> rhs;
} }
constexpr auto operator==(const CommonCode &c1, const CommonCode &c2) { constexpr auto operator==(const CommonCode &lhs, const CommonCode &rhs) {
return c1.code_ == c2.code_; return lhs.code_ == rhs.code_;
} }
constexpr auto operator<=>(const CommonCode &c1, const CommonCode &c2) { constexpr auto operator<=>(const CommonCode &lhs, const CommonCode &rhs) {
return c1.code_ <=> c2.code_; return lhs.code_ <=> rhs.code_;
} }
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //

Loading…
Cancel
Save