diff --git a/include/fmt/compile.h b/include/fmt/compile.h index e0933754..ea0007a4 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -13,6 +13,12 @@ #include "format.h" +#if !defined(FMT_USE_NONTYPE_TEMPLATE_PARAMETERS) && \ + defined(__cpp_nontype_template_parameter_class) && \ + (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 903) +# define FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +#endif + FMT_BEGIN_NAMESPACE namespace detail { @@ -37,9 +43,8 @@ struct is_compiled_string : std::is_base_of {}; */ #define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::detail::compiled_string) -#if defined(__cpp_nontype_template_parameter_class) && \ - (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 903) -template struct fixed_string { +#ifdef FMT_USE_NONTYPE_TEMPLATE_PARAMETERS +template struct fixed_string { constexpr fixed_string(const Char (&str)[N + 1]) { copy_str(static_cast(str), str + N, data); @@ -47,10 +52,10 @@ template struct fixed_string { Char data[N]{}; }; -template +template fixed_string(const Char (&str)[N]) -> fixed_string; -template Str> +template Str> struct udl_compiled_string : compiled_string { using char_type = Char; constexpr operator basic_string_view() const { @@ -720,8 +725,7 @@ size_t formatted_size(const CompiledFormat& cf, const Args&... args) { return format_to(detail::counting_iterator(), cf, args...).count(); } -#if defined(__cpp_nontype_template_parameter_class) && \ - (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 903) +#ifdef FMT_USE_NONTYPE_TEMPLATE_PARAMETERS inline namespace literals { template constexpr detail::udl_compiled_string, diff --git a/test/compile-test.cc b/test/compile-test.cc index ffd2fdf0..30bb7fc7 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -179,8 +179,7 @@ TEST(CompileTest, Empty) { } #endif -#if defined(__cpp_nontype_template_parameter_class) && \ - (!FMT_GCC_VERSION || FMT_GCC_VERSION >= 903) +#ifdef FMT_USE_NONTYPE_TEMPLATE_PARAMETERS TEST(CompileTest, CompileFormatStringLiteral) { using namespace fmt::literals; EXPECT_EQ("42", fmt::format("{}"_cf, 42));