Skip to content

Commit

Permalink
atomic_flag formatting (#3594)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexGuteniev authored Aug 25, 2023
1 parent a21690b commit 9b74160
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,5 +448,18 @@ struct formatter<std::atomic<T>, Char,
}
};

#ifdef __cpp_lib_atomic_flag_test
FMT_EXPORT
template <typename Char>
struct formatter<std::atomic_flag, Char>
: formatter<bool, Char> {
template <typename FormatContext>
auto format(const std::atomic_flag& v, FormatContext& ctx) const
-> decltype(ctx.out()) {
return formatter<bool, Char>::format(v.test(), ctx);
}
};
#endif // __cpp_lib_atomic_flag_test

FMT_END_NAMESPACE
#endif // FMT_STD_H_
11 changes: 11 additions & 0 deletions test/std-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,14 @@ TEST(std_test, format_atomic) {
const std::atomic<bool> cb(true);
EXPECT_EQ(fmt::format("{}", cb), "true");
}

#ifdef __cpp_lib_atomic_flag_test
TEST(std_test, format_atomic_flag) {
std::atomic_flag f = ATOMIC_FLAG_INIT;
(void) f.test_and_set();
EXPECT_EQ(fmt::format("{}", f), "true");

const std::atomic_flag cf = ATOMIC_FLAG_INIT;
EXPECT_EQ(fmt::format("{}", cf), "false");
}
#endif // __cpp_lib_atomic_flag_test

0 comments on commit 9b74160

Please sign in to comment.