Skip to content

Commit

Permalink
fix: make snowflake formattable again (#943)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 authored Oct 11, 2023
1 parent b2e361e commit 4a113c6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/dpp/snowflake.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,18 @@ class DPP_EXPORT snowflake final {
constexpr uint16_t get_increment() const noexcept {
return static_cast<uint16_t>(value & 0xFFF);
}

/**
* @brief Helper function for libfmt so that a snowflake can be directly formatted as a uint64_t.
*
* @see https://fmt.dev/latest/api.html#formatting-user-defined-types
* @return uint64_t snowflake ID
*/
friend constexpr uint64_t format_as(snowflake s) noexcept {
/* note: this function must stay as "friend" - this declares it as a free function but makes it invisible unless the argument is snowflake
* this effectively means no implicit conversions are performed to snowflake, for example format_as(0) doesn't call this function */
return s.value;
}
};

} // namespace dpp
Expand Down

0 comments on commit 4a113c6

Please sign in to comment.