Make FMT_COMPILE fallback on runtime without if constexpr (#2261)
This commit is contained in:
parent
0cd0fb9184
commit
355be4b13f
@ -114,7 +114,11 @@ struct is_compiled_string : std::is_base_of<compiled_string, S> {};
|
||||
std::string s = fmt::format(FMT_COMPILE("{}"), 42);
|
||||
\endrst
|
||||
*/
|
||||
#define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string)
|
||||
#ifdef __cpp_if_constexpr
|
||||
# define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string)
|
||||
#else
|
||||
# define FMT_COMPILE(s) FMT_STRING(s)
|
||||
#endif
|
||||
|
||||
#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
|
||||
template <typename Char, size_t N, fixed_string<Char, N> Str>
|
||||
|
@ -155,6 +155,12 @@ TEST(CompileTest, EmptyFormatString) {
|
||||
EXPECT_EQ(fmt::format(f), "");
|
||||
}
|
||||
|
||||
TEST(CompileTest, CompileFallback) {
|
||||
// FMT_COMPILE should fallback on runtime formatting when `if constexpr` is
|
||||
// not available.
|
||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42));
|
||||
}
|
||||
|
||||
#ifdef __cpp_if_constexpr
|
||||
TEST(CompileTest, FormatDefault) {
|
||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42));
|
||||
|
Loading…
Reference in New Issue
Block a user