diff --git a/dht/i_partitioner.cc b/dht/i_partitioner.cc index bb1fb2eb34..e4998c955b 100644 --- a/dht/i_partitioner.cc +++ b/dht/i_partitioner.cc @@ -10,6 +10,7 @@ #include "sharder.hh" #include #include +#include "dht/ring_position.hh" #include "dht/token-sharding.hh" #include "utils/class_registrator.hh" #include @@ -58,26 +59,6 @@ std::ostream& operator<<(std::ostream& out, const decorated_key& dk) { return out; } -std::ostream& operator<<(std::ostream& out, partition_ranges_view v) { - out << "{"; - - if (v.empty()) { - out << " }"; - return out; - } - - auto it = v.begin(); - out << *it; - ++it; - - for (;it != v.end(); ++it) { - out << ", " << *it; - } - - out << "}"; - return out; -} - std::unique_ptr make_partitioner(sstring partitioner_name) { try { return create_object(partitioner_name); @@ -149,11 +130,6 @@ decorated_key::less_comparator::operator()(const decorated_key& lhs, const ring_ return lhs.tri_compare(*s, rhs) < 0; } -std::ostream& operator<<(std::ostream& out, const i_partitioner& p) { - out << "{partitioner name = " << p.name(); - return out << "}"; -} - unsigned static_shard_of(const schema& s, const token& t) { return s.get_sharder().shard_of(t); } @@ -518,3 +494,12 @@ auto fmt::formatter::format(const dht::ring_position& pos, f } return fmt::format_to(out, "}}"); } + +auto fmt::formatter::format(const dht::partition_ranges_view& v, fmt::format_context& ctx) const + -> decltype(ctx.out()) { + auto out = fmt::format_to(ctx.out(), "{{"); + for (auto& range : v) { + out = fmt::format_to(out, "{}", range); + } + return fmt::format_to(out, "}}"); +} diff --git a/dht/i_partitioner.hh b/dht/i_partitioner.hh index 05117b0093..bdbc93756f 100644 --- a/dht/i_partitioner.hh +++ b/dht/i_partitioner.hh @@ -73,8 +73,6 @@ public: } }; -std::ostream& operator<<(std::ostream& out, const i_partitioner& p); - // Returns the owning shard number for vnode-based replication strategies. // Use table::shard_of() for the general case. unsigned static_shard_of(const schema&, const token&); @@ -120,3 +118,10 @@ dht::token first_token(const dht::partition_range&); std::optional is_single_shard(const dht::sharder&, const schema&, const dht::partition_range&); } // dht + +template <> struct fmt::formatter : fmt::formatter { + template + auto format(const dht::i_partitioner& p, FormatContext& ctx) const { + return fmt::format_to(ctx.out(), "{{partitioner name = {}}}", p.name()); + } +}; diff --git a/dht/ring_position.hh b/dht/ring_position.hh index 0aeeacfef9..c125e44f42 100644 --- a/dht/ring_position.hh +++ b/dht/ring_position.hh @@ -486,8 +486,6 @@ public: const dht::partition_range* end() const { return _data + _size; } }; -std::ostream& operator<<(std::ostream& out, partition_ranges_view v); - } // namespace dht template<> @@ -509,3 +507,8 @@ struct fmt::formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } auto format(const dht::ring_position& pos, fmt::format_context& ctx) const -> decltype(ctx.out()); }; + +template <> struct fmt::formatter : fmt::formatter { + auto format(const dht::partition_ranges_view&, fmt::format_context& ctx) const + -> decltype(ctx.out()); +};