mirror of
https://github.com/ceph/ceph
synced 2025-04-11 04:02:04 +00:00
Merge pull request #47255 from tchaikov/wip-fmt-containers
include/types_fmt: use fmt::join() to format containers Reviewed-by: Ronen Friedman <rfriedma@redhat.com>
This commit is contained in:
commit
f85f60f366
@ -296,7 +296,7 @@ include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/xxHash")
|
|||||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/rapidjson/include")
|
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/rapidjson/include")
|
||||||
|
|
||||||
option(WITH_FMT_HEADER_ONLY "use header-only version of fmt library" OFF)
|
option(WITH_FMT_HEADER_ONLY "use header-only version of fmt library" OFF)
|
||||||
find_package(fmt 6.0.0 QUIET)
|
find_package(fmt 7.0.0 QUIET)
|
||||||
if(fmt_FOUND)
|
if(fmt_FOUND)
|
||||||
include_directories(SYSTEM "${fmt_INCLUDE_DIR}")
|
include_directories(SYSTEM "${fmt_INCLUDE_DIR}")
|
||||||
else()
|
else()
|
||||||
@ -306,6 +306,8 @@ else()
|
|||||||
add_subdirectory(fmt)
|
add_subdirectory(fmt)
|
||||||
set(BUILD_SHARED_LIBS ${old_BUILD_SHARED_LIBS})
|
set(BUILD_SHARED_LIBS ${old_BUILD_SHARED_LIBS})
|
||||||
unset(old_BUILD_SHARED_LIBS)
|
unset(old_BUILD_SHARED_LIBS)
|
||||||
|
target_compile_definitions(fmt PUBLIC
|
||||||
|
$<$<BOOL:${WIN32}>:FMT_USE_TZSET=0>)
|
||||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/fmt/include")
|
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/fmt/include")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
2
src/fmt
2
src/fmt
@ -1 +1 @@
|
|||||||
Subproject commit 427b53405442872decb69d9735db0fa64106ebe2
|
Subproject commit b6f4ceaed0a0a24ccf575fab6c56dd50ccf6f1a9
|
@ -11,6 +11,17 @@
|
|||||||
|
|
||||||
#include "include/types.h"
|
#include "include/types.h"
|
||||||
|
|
||||||
|
template <class Key, class T>
|
||||||
|
struct fmt::formatter<std::pair<const Key, T>> {
|
||||||
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const std::pair<const Key, T>& p, FormatContext& ctx)
|
||||||
|
{
|
||||||
|
return fmt::format_to(ctx.out(), "{}={}", p.first, p.second);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template <class A, class B, class Comp, class Alloc>
|
template <class A, class B, class Comp, class Alloc>
|
||||||
struct fmt::formatter<std::map<A, B, Comp, Alloc>> {
|
struct fmt::formatter<std::map<A, B, Comp, Alloc>> {
|
||||||
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
||||||
@ -18,59 +29,39 @@ struct fmt::formatter<std::map<A, B, Comp, Alloc>> {
|
|||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const std::map<A, B, Comp, Alloc>& m, FormatContext& ctx)
|
auto format(const std::map<A, B, Comp, Alloc>& m, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
std::string_view sep = "{";
|
return fmt::format_to(ctx.out(), "{{{}}}", fmt::join(m, ","));
|
||||||
for (const auto& [k, v] : m) {
|
|
||||||
fmt::format_to(ctx.out(), "{}{}={}", sep, k, v);
|
|
||||||
sep = ",";
|
|
||||||
}
|
|
||||||
return fmt::format_to(ctx.out(), "}}");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class A>
|
template <class... Args>
|
||||||
struct fmt::formatter<std::list<A>> {
|
struct fmt::formatter<std::list<Args...>> {
|
||||||
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const std::list<A>& l, FormatContext& ctx)
|
auto format(const std::list<Args...>& l, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
std::string_view sep = "";
|
return fmt::format_to(ctx.out(), "{}", fmt::join(l, ","));
|
||||||
for (const auto& e : l) {
|
|
||||||
fmt::format_to(ctx.out(), "{}{}", sep, e);
|
|
||||||
sep = ",";
|
|
||||||
}
|
|
||||||
return ctx.out();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class A>
|
template <class... Args>
|
||||||
struct fmt::formatter<std::vector<A>> {
|
struct fmt::formatter<std::vector<Args...>> {
|
||||||
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const std::vector<A>& l, FormatContext& ctx)
|
auto format(const std::vector<Args...>& v, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
std::string_view sep = "[";
|
return fmt::format_to(ctx.out(), "[{}]", fmt::join(v, ","));
|
||||||
for (const auto& e : l) {
|
|
||||||
fmt::format_to(ctx.out(), "{}{}", sep, e);
|
|
||||||
sep = ",";
|
|
||||||
}
|
|
||||||
return fmt::format_to(ctx.out(), "]");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class A>
|
template <class... Args>
|
||||||
struct fmt::formatter<std::set<A>> {
|
struct fmt::formatter<std::set<Args...>> {
|
||||||
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
template <typename FormatContext>
|
template <typename FormatContext>
|
||||||
auto format(const std::set<A>& l, FormatContext& ctx)
|
auto format(const std::set<Args...>& s, FormatContext& ctx)
|
||||||
{
|
{
|
||||||
std::string_view sep = "";
|
return fmt::format_to(ctx.out(), "{}", fmt::join(s, ","));
|
||||||
for (const auto& e : l) {
|
|
||||||
fmt::format_to(ctx.out(), "{}{}", sep, e);
|
|
||||||
sep = ",";
|
|
||||||
}
|
|
||||||
return ctx.out();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user