mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-24 00:32:15 +00:00
service/paxos: add fmt::formatter for paxos::proposal
before this change, we rely on the default-generated fmt::formatter created from operator<<, but fmt v10 dropped the default-generated formatter. in this change, we define formatters for `service::paxos::proposal`, but its operator<< is preserved, as it is still used by our generic formatter for std::tuple<> which uses operator<< for printing the elements in it, so operator<< of this class is indirectly used. Refs #13245 Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
This commit is contained in:
@@ -9,13 +9,7 @@
|
||||
|
||||
#include "proposal.hh"
|
||||
|
||||
namespace service {
|
||||
|
||||
namespace paxos {
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const proposal& proposal) {
|
||||
return os << "proposal(" << proposal.ballot << ")";
|
||||
auto fmt::formatter<service::paxos::proposal>::format(const service::paxos::proposal& proposal,
|
||||
fmt::format_context& ctx) const -> decltype(ctx.out()) {
|
||||
return fmt::format_to(ctx.out(), "proposal({})", proposal.ballot);
|
||||
}
|
||||
|
||||
} // end of namespace "paxos"
|
||||
} // endf of namespace "service"
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "mutation/frozen_mutation.hh"
|
||||
#include <fmt/core.h>
|
||||
|
||||
namespace service {
|
||||
|
||||
@@ -45,8 +46,19 @@ inline bool operator>(const proposal& lhs, const proposal& rhs) {
|
||||
return lhs.ballot.timestamp() > rhs.ballot.timestamp();
|
||||
}
|
||||
|
||||
// Used for logging and debugging.
|
||||
std::ostream& operator<<(std::ostream& os, const proposal& proposal);
|
||||
|
||||
} // end of namespace "paxos"
|
||||
} // end of namespace "service"
|
||||
|
||||
// Used for logging and debugging.
|
||||
template <> struct fmt::formatter<service::paxos::proposal> : fmt::formatter<std::string_view> {
|
||||
auto format(const service::paxos::proposal&, fmt::format_context& ctx) const -> decltype(ctx.out());
|
||||
};
|
||||
|
||||
namespace service::paxos {
|
||||
|
||||
static inline std::ostream& operator<<(std::ostream& os, const proposal& proposal) {
|
||||
fmt::print(os, "{}", proposal);
|
||||
return os;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user