Files
scylladb/utils/to_string.cc
Kefu Chai 007d7f1355 utils: add fmt::formatter for std::strong_ordering and friends
before this change, we rely on the default-generated fmt::formatter created
from operator<<, but fmt v10 dropped the default-generated formatter.

in this change, we define formatters for

* std::strong_ordering
* std::weak_ordering
* std::partial_ordering

and their operator<<:s are moved to test/lib/test_utils.{hh,cc}, as they
are only used by Boost.test.

Refs #13245

Signed-off-by: Kefu Chai <kefu.chai@scylladb.com>
2024-03-12 14:53:55 +08:00

45 lines
1.3 KiB
C++

/*
* Copyright (C) 2015-present ScyllaDB
*/
/*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "utils/to_string.hh"
auto fmt::formatter<std::strong_ordering>::format(std::strong_ordering order, fmt::format_context& ctx) const
-> decltype(ctx.out()) {
if (order > 0) {
return fmt::format_to(ctx.out(), "gt");
} else if (order < 0) {
return fmt::format_to(ctx.out(), "lt");
} else {
return fmt::format_to(ctx.out(), "eq");
}
}
auto fmt::formatter<std::weak_ordering>::format(std::weak_ordering order, fmt::format_context& ctx) const
-> decltype(ctx.out()) {
if (order > 0) {
return fmt::format_to(ctx.out(), "gt");
} else if (order < 0) {
return fmt::format_to(ctx.out(), "lt");
} else {
return fmt::format_to(ctx.out(), "eq");
}
}
auto fmt::formatter<std::partial_ordering>::format(std::partial_ordering order, fmt::format_context& ctx) const
-> decltype(ctx.out()) {
if (order == std::partial_ordering::unordered) {
return fmt::format_to(ctx.out(), "unordered");
} else if (order > 0) {
return fmt::format_to(ctx.out(), "gt");
} else if (order < 0) {
return fmt::format_to(ctx.out(), "lt");
} else {
return fmt::format_to(ctx.out(), "eq");
}
}