From: Kefu Chai Date: Tue, 22 Nov 2022 04:26:19 +0000 (+0800) Subject: *: specialize fmt::formatter<> for formatting using {fmt} X-Git-Tag: v18.1.0~844^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=01f6bef6e5250bf568d9d5f6acf37de64236159a;p=ceph.git *: specialize fmt::formatter<> for formatting using {fmt} in {fmt} v9, fmt::formatter<> is not defined automatically for the types with operator<<, we need to define them explictly. so in this change, the types printed using `fmt::print()` or `fmt::format()` are equiped with fmt::formatter<> to appease {fmt} v9. Signed-off-by: Kefu Chai --- diff --git a/src/common/ceph_time.h b/src/common/ceph_time.h index 920480292740..22429fa282a8 100644 --- a/src/common/ceph_time.h +++ b/src/common/ceph_time.h @@ -533,4 +533,9 @@ template ostream& operator<<(ostream& m, const chrono::duration& t); } +#if FMT_VERSION >= 90000 +template +struct fmt::formatter> : fmt::ostream_formatter {}; +#endif + #endif // COMMON_CEPH_TIME_H diff --git a/src/common/hobject.h b/src/common/hobject.h index 28f314d7935e..34191ccf5ec8 100644 --- a/src/common/hobject.h +++ b/src/common/hobject.h @@ -15,6 +15,10 @@ #ifndef __CEPH_OS_HOBJECT_H #define __CEPH_OS_HOBJECT_H +#if FMT_VERSION >= 90000 +#include +#endif + #include "include/types.h" #include "json_spirit/json_spirit_value.h" @@ -501,6 +505,10 @@ namespace std { std::ostream& operator<<(std::ostream& out, const ghobject_t& o); +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#endif + extern int cmp(const ghobject_t& l, const ghobject_t& r); diff --git a/src/common/snap_types.h b/src/common/snap_types.h index 1705f8834cd2..70b72f10563d 100644 --- a/src/common/snap_types.h +++ b/src/common/snap_types.h @@ -74,4 +74,8 @@ inline std::ostream& operator<<(std::ostream& out, const SnapContext& snapc) { return out << snapc.seq << "=" << snapc.snaps; } +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#endif + #endif diff --git a/src/crush/CrushLocation.h b/src/crush/CrushLocation.h index 678135c2e42a..24f43068d617 100644 --- a/src/crush/CrushLocation.h +++ b/src/crush/CrushLocation.h @@ -35,3 +35,7 @@ private: std::ostream& operator<<(std::ostream& os, const CrushLocation& loc); } #endif + +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#endif diff --git a/src/include/types.h b/src/include/types.h index e62ef446cb1b..12a0b2a6dbff 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -611,6 +611,10 @@ inline std::ostream &operator<<(std::ostream &out, const sha_digest_t &b) { return out << str; } +#if FMT_VERSION >= 90000 +template struct fmt::formatter> : fmt::ostream_formatter {}; +#endif + using sha1_digest_t = sha_digest_t<20>; WRITE_CLASS_ENCODER(sha1_digest_t) diff --git a/src/include/uuid.h b/src/include/uuid.h index ac4098a16af2..6a30aa621c44 100644 --- a/src/include/uuid.h +++ b/src/include/uuid.h @@ -96,5 +96,8 @@ inline bool operator>(const uuid_d& l, const uuid_d& r) { return l.to_string() > r.to_string(); } +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#endif #endif diff --git a/src/msg/Message.h b/src/msg/Message.h index f6d34d8002ce..3a18c82a2806 100644 --- a/src/msg/Message.h +++ b/src/msg/Message.h @@ -15,6 +15,7 @@ #ifndef CEPH_MESSAGE_H #define CEPH_MESSAGE_H +#include #include #include #include @@ -570,4 +571,9 @@ MURef make_message(Args&&... args) { return {new T(std::forward(args)...), TOPNSPC::common::UniquePtrDeleter{}}; } } + +#if FMT_VERSION >= 90000 +template M> struct fmt::formatter : fmt::ostream_formatter {}; +#endif + #endif diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index a33545d916f3..65cfee514bba 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -18,6 +18,9 @@ #include #include +#if FMT_VERSION >= 90000 +#include +#endif #include "include/ceph_features.h" #include "include/types.h" @@ -547,6 +550,9 @@ struct entity_addr_t { WRITE_CLASS_ENCODER_FEATURES(entity_addr_t) std::ostream& operator<<(std::ostream& out, const entity_addr_t &addr); +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#endif inline bool operator==(const entity_addr_t& a, const entity_addr_t& b) { return memcmp(&a, &b, sizeof(a)) == 0; } inline bool operator!=(const entity_addr_t& a, const entity_addr_t& b) { return memcmp(&a, &b, sizeof(a)) != 0; } @@ -735,6 +741,9 @@ struct entity_addrvec_t { } }; WRITE_CLASS_ENCODER_FEATURES(entity_addrvec_t); +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#endif namespace std { template<> struct hash { diff --git a/src/osd/osd_types.h b/src/osd/osd_types.h index f4a585362fa6..48a5c6401fc6 100644 --- a/src/osd/osd_types.h +++ b/src/osd/osd_types.h @@ -785,6 +785,10 @@ inline std::ostream& operator<<(std::ostream& out, const coll_t& c) { return out; } +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#endif + namespace std { template<> struct hash { size_t operator()(const coll_t &c) const { @@ -4711,6 +4715,9 @@ struct pg_missing_item { }; WRITE_CLASS_ENCODER_FEATURES(pg_missing_item) std::ostream& operator<<(std::ostream& out, const pg_missing_item &item); +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#endif class pg_missing_const_i { public: diff --git a/src/osd/osd_types_fmt.h b/src/osd/osd_types_fmt.h index fb555f3cb623..2a43fe893ee5 100644 --- a/src/osd/osd_types_fmt.h +++ b/src/osd/osd_types_fmt.h @@ -324,3 +324,12 @@ struct fmt::formatter { bool debug_log{false}; }; + +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template <> struct fmt::formatter : fmt::ostream_formatter {}; +template struct fmt::formatter> : fmt::ostream_formatter {}; +#endif diff --git a/src/osd/recovery_types.h b/src/osd/recovery_types.h index 73a62188289e..cffb2b7ea4c0 100644 --- a/src/osd/recovery_types.h +++ b/src/osd/recovery_types.h @@ -93,3 +93,6 @@ struct BackfillInterval { std::ostream &operator<<(std::ostream &out, const BackfillInterval &bi); +#if FMT_VERSION >= 90000 +template <> struct fmt::formatter : fmt::ostream_formatter {}; +#endif