Skip to content

Commit 45ed657

Browse files
committed
Cleanup locking
1 parent a5cd004 commit 45ed657

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

include/fmt/base.h

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ struct formatter {
623623
formatter() = delete;
624624
};
625625

626+
template <typename T, typename Enable = void>
627+
struct locking : std::false_type {};
628+
626629
/// Reports a format error at compile time or, via a `format_error` exception,
627630
/// at runtime.
628631
// This function is intentionally not constexpr to give a compile-time error.
@@ -2292,8 +2295,6 @@ template <typename T, typename Char, type TYPE> struct native_formatter {
22922295
dynamic_format_specs<Char> specs_;
22932296

22942297
public:
2295-
using nonlocking = void;
2296-
22972298
FMT_CONSTEXPR auto parse(parse_context<Char>& ctx) -> const Char* {
22982299
if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin();
22992300
auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE);
@@ -2313,19 +2314,12 @@ template <typename T, typename Char, type TYPE> struct native_formatter {
23132314
-> decltype(ctx.out());
23142315
};
23152316

2316-
template <typename T, typename Enable = void>
2317-
struct locking
2318-
: bool_constant<mapped_type_constant<T>::value == type::custom_type> {};
2319-
template <typename T>
2320-
struct locking<T, void_t<typename formatter<remove_cvref_t<T>>::nonlocking>>
2321-
: std::false_type {};
2322-
2323-
template <typename T = int> constexpr inline auto is_locking() -> bool {
2324-
return locking<T>::value;
2317+
template <typename T = int> constexpr auto is_locking() -> bool {
2318+
return locking<remove_cvref_t<T>>::value;
23252319
}
23262320
template <typename T1, typename T2, typename... Tail>
2327-
constexpr inline auto is_locking() -> bool {
2328-
return locking<T1>::value || is_locking<T2, Tail...>();
2321+
constexpr auto is_locking() -> bool {
2322+
return locking<remove_cvref_t<T1>>::value || is_locking<T2, Tail...>();
23292323
}
23302324

23312325
FMT_API void vformat_to(buffer<char>& buf, string_view fmt, format_args args,
@@ -2835,8 +2829,8 @@ FMT_INLINE void print(format_string<T...> fmt, T&&... args) {
28352829
vargs<T...> va = {{args...}};
28362830
if FMT_CONSTEXPR20 (!detail::use_utf8)
28372831
return detail::vprint_mojibake(stdout, fmt.str, va, false);
2838-
return detail::is_locking<T...>() ? vprint_buffered(stdout, fmt.str, va)
2839-
: vprint(fmt.str, va);
2832+
detail::is_locking<T...>() ? vprint_buffered(stdout, fmt.str, va)
2833+
: vprint(fmt.str, va);
28402834
}
28412835

28422836
/**
@@ -2852,8 +2846,8 @@ FMT_INLINE void print(FILE* f, format_string<T...> fmt, T&&... args) {
28522846
vargs<T...> va = {{args...}};
28532847
if FMT_CONSTEXPR20 (!detail::use_utf8)
28542848
return detail::vprint_mojibake(f, fmt.str, va, false);
2855-
return detail::is_locking<T...>() ? vprint_buffered(f, fmt.str, va)
2856-
: vprint(f, fmt.str, va);
2849+
detail::is_locking<T...>() ? vprint_buffered(f, fmt.str, va)
2850+
: vprint(f, fmt.str, va);
28572851
}
28582852

28592853
/// Formats `args` according to specifications in `fmt` and writes the output
@@ -2869,7 +2863,7 @@ FMT_INLINE void println(FILE* f, format_string<T...> fmt, T&&... args) {
28692863
/// to `stdout` followed by a newline.
28702864
template <typename... T>
28712865
FMT_INLINE void println(format_string<T...> fmt, T&&... args) {
2872-
return fmt::println(stdout, fmt, static_cast<T&&>(args)...);
2866+
fmt::println(stdout, fmt, static_cast<T&&>(args)...);
28732867
}
28742868

28752869
FMT_PRAGMA_CLANG(diagnostic pop)

test/format-test.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1953,6 +1953,8 @@ template <> struct formatter<deadlockable> {
19531953
return format_to(ctx.out(), "{}", d.value);
19541954
}
19551955
};
1956+
1957+
template <> struct locking<deadlockable> : std::true_type {};
19561958
FMT_END_NAMESPACE
19571959

19581960
TEST(format_test, locking_formatter) {

0 commit comments

Comments
 (0)