mirror of
https://github.com/fmtlib/fmt.git
synced 2025-04-10 21:44:19 +00:00
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);
|
std::string s = fmt::format(FMT_COMPILE("{}"), 42);
|
||||||
\endrst
|
\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
|
#if FMT_USE_NONTYPE_TEMPLATE_PARAMETERS
|
||||||
template <typename Char, size_t N, fixed_string<Char, N> Str>
|
template <typename Char, size_t N, fixed_string<Char, N> Str>
|
||||||
|
@ -155,6 +155,12 @@ TEST(CompileTest, EmptyFormatString) {
|
|||||||
EXPECT_EQ(fmt::format(f), "");
|
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
|
#ifdef __cpp_if_constexpr
|
||||||
TEST(CompileTest, FormatDefault) {
|
TEST(CompileTest, FormatDefault) {
|
||||||
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42));
|
EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), 42));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user