Constexpr formatted_size (#3026)

* Constexpr formatted_size

* Add C++20 tests for gcc 9 and 10

* Adjust unit test to require __cpp_lib_bit_cast
This commit is contained in:
Mark Santaniello
2022-08-10 09:35:30 -07:00
committed by GitHub
parent 7fb8d33f9d
commit fd93b633b8
3 changed files with 17 additions and 13 deletions

View File

@ -227,10 +227,14 @@ TEST(compile_test, format_to_n) {
EXPECT_STREQ("2a", buffer);
}
TEST(compile_test, formatted_size) {
EXPECT_EQ(2, fmt::formatted_size(FMT_COMPILE("{0}"), 42));
EXPECT_EQ(5, fmt::formatted_size(FMT_COMPILE("{0:<4.2f}"), 42.0));
#ifdef __cpp_lib_bit_cast
TEST(compile_test, constexpr_formatted_size) {
FMT_CONSTEXPR20 size_t s1 = fmt::formatted_size(FMT_COMPILE("{0}"), 42);
EXPECT_EQ(2, s1);
FMT_CONSTEXPR20 size_t s2 = fmt::formatted_size(FMT_COMPILE("{0:<4.2f}"), 42.0);
EXPECT_EQ(5, s2);
}
#endif
TEST(compile_test, text_and_arg) {
EXPECT_EQ(">>>42<<<", fmt::format(FMT_COMPILE(">>>{}<<<"), 42));