]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
src: migrate to fmt::formattable for format support
authorKefu Chai <tchaikov@gmail.com>
Wed, 26 Mar 2025 03:43:43 +0000 (11:43 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sat, 29 Mar 2025 13:18:01 +0000 (21:18 +0800)
Replace custom has_formatter concept with fmtlib's fmt::formattable

- Deprecate usage of fmt::has_formatter
- Resolve compiler warnings with recent fmtlib versions

The custom concept of has_formatter is no longer necessary with
recent updates to the fmtlib library, as fmt::formattable was introduced
in fmtlib v11.0.0. By switching to fmt::formattable, we simplify our
code and stop using the deprecated `fmt::has_formatter` template.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/common/bitset_set.h
src/common/fmt_common.h
src/common/interval_map.h
src/common/mini_flat_map.h
src/crimson/osd/scrub/scrub_machine.h
src/include/interval_set.h
src/osd/scrubber/scrub_machine.h

index 5bd0be0ce07cb236dad1cd263c70ac4848566285..12c98de99a4cbbe80bf3d79bb5eeccbc29d0ade7 100644 (file)
@@ -412,7 +412,7 @@ class bitset_set {
   }
 
   std::string fmt_print() const
-  requires has_formatter<KeyT> {
+  requires fmt::formattable<KeyT> {
     std::string s = "{";
     int c = (int)size();
     for (auto k : *this) {
index 474f6fbc3247716f4b4e96b477631c464ab933ed..cd891bfc93fd5852f894f1a633a874ddd9cef636 100644 (file)
@@ -2,7 +2,9 @@
 // vim: ts=8 sw=2 smarttab
 #pragma once
 
+#include <fmt/base.h>
 #include <optional>
+#include <type_traits>
 
 /**
  * \file default fmtlib formatters for specifically-tagged types
  * such classes in Crimson.
  */
 
-template <typename T>
-concept has_formatter = fmt::has_formatter<T, fmt::format_context>::value;
+#if FMT_VERSION < 110000
+// TODO: drop me once fmt v11 is required
+namespace fmt {
+  template <typename T, typename Char = char>
+  concept formattable = is_formattable<std::remove_reference_t<T>, Char>::value>;
+}
+#endif
 
 /**
  * Tagging classes that provide support for default fmtlib formatting,
index e363d938b78c1dbb358f43c8cb890b7bdecdc1f8..470bfb37618f05444cac3b5183ebfe435d811440 100644 (file)
@@ -324,7 +324,7 @@ public:
   }
 
   std::string fmt_print() const
-  requires has_formatter<K> {
+  requires fmt::formattable<K> {
     std::string str = "{";
     bool first = true;
     for (auto &&i: *this) {
index 5e880f50d70f24f574191b2f30ceb447ff435c60..46abda5138729992897b6f634bad1d604de6623a 100644 (file)
@@ -495,7 +495,7 @@ class mini_flat_map {
   }
 
   std::string fmt_print() const
-  requires has_formatter<KeyT> && has_formatter<ValueT> {
+  requires fmt::formattable<KeyT> && fmt::formattable<ValueT> {
     int c = (int)_size;
     std::string s = "{";
     for (auto&& [k, v] : *this) {
index f6cec5cba71ab079129d77ac124f84571b70e5bd..511e8aa865f3aa27b5b970d24f01b70969526ead 100644 (file)
@@ -49,7 +49,7 @@ struct simple_event_t : sc::event<T> {
   }
 };
 
-template <typename T, has_formatter V>
+template <typename T, fmt::formattable V>
 struct value_event_t : sc::event<T> {
   const V value;
 
index e93ba7601e287657a3831933a450512f20cb2cf6..4ba12666e4f906df398bc00a62d62150ce52d506 100644 (file)
@@ -263,7 +263,7 @@ class interval_set {
   }
 
   std::string fmt_print() const
-  requires has_formatter<T> {
+  requires fmt::formattable<T> {
     std::string s = "[";
     bool first = true;
     for (const auto& [start, len] : *this) {
index f7f739692bf9ee73ab055217d8f83c10b55ebb40..5ae895d86df89a73051ab9a685ea664ebca8105e 100644 (file)
@@ -105,7 +105,7 @@ OP_EV(ReplicaReserveReq);
 /// explicit release request from the Primary
 OP_EV(ReplicaRelease);
 
-template <typename T, has_formatter V>
+template <typename T, fmt::formattable V>
 struct value_event_t : sc::event<T> {
   const V value;