Skip to content

Commit 0dc1578

Browse files
committed
src: migrate to fmt::formattable for format support
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 <[email protected]>
1 parent bb4d512 commit 0dc1578

File tree

7 files changed

+15
-8
lines changed

7 files changed

+15
-8
lines changed

src/common/bitset_set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class bitset_set {
412412
}
413413

414414
std::string fmt_print() const
415-
requires has_formatter<KeyT> {
415+
requires fmt::formattable<KeyT> {
416416
std::string s = "{";
417417
int c = (int)size();
418418
for (auto k : *this) {

src/common/fmt_common.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// vim: ts=8 sw=2 smarttab
33
#pragma once
44

5+
#include <fmt/base.h>
56
#include <optional>
7+
#include <type_traits>
68

79
/**
810
* \file default fmtlib formatters for specifically-tagged types
@@ -17,8 +19,13 @@
1719
* such classes in Crimson.
1820
*/
1921

20-
template <typename T>
21-
concept has_formatter = fmt::has_formatter<T, fmt::format_context>::value;
22+
#if FMT_VERSION < 110000
23+
// TODO: drop me once fmt v11 is required
24+
namespace fmt {
25+
template <typename T, typename Char = char>
26+
concept formattable = is_formattable<std::remove_reference_t<T>, Char>::value>;
27+
}
28+
#endif
2229

2330
/**
2431
* Tagging classes that provide support for default fmtlib formatting,

src/common/interval_map.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ class interval_map {
324324
}
325325

326326
std::string fmt_print() const
327-
requires has_formatter<K> {
327+
requires fmt::formattable<K> {
328328
std::string str = "{";
329329
bool first = true;
330330
for (auto &&i: *this) {

src/common/mini_flat_map.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ class mini_flat_map {
495495
}
496496

497497
std::string fmt_print() const
498-
requires has_formatter<KeyT> && has_formatter<ValueT> {
498+
requires fmt::formattable<KeyT> && fmt::formattable<ValueT> {
499499
int c = (int)_size;
500500
std::string s = "{";
501501
for (auto&& [k, v] : *this) {

src/crimson/osd/scrub/scrub_machine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct simple_event_t : sc::event<T> {
4949
}
5050
};
5151

52-
template <typename T, has_formatter V>
52+
template <typename T, fmt::formattable V>
5353
struct value_event_t : sc::event<T> {
5454
const V value;
5555

src/include/interval_set.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class interval_set {
263263
}
264264

265265
std::string fmt_print() const
266-
requires has_formatter<T> {
266+
requires fmt::formattable<T> {
267267
std::string s = "[";
268268
bool first = true;
269269
for (const auto& [start, len] : *this) {

src/osd/scrubber/scrub_machine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ OP_EV(ReplicaReserveReq);
105105
/// explicit release request from the Primary
106106
OP_EV(ReplicaRelease);
107107

108-
template <typename T, has_formatter V>
108+
template <typename T, fmt::formattable V>
109109
struct value_event_t : sc::event<T> {
110110
const V value;
111111

0 commit comments

Comments
 (0)