diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 337bed31..fbe1ebff 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -326,6 +326,17 @@ class compiled_format : private compiled_format_base { : compiled_format_base(format_str), format_str_(format_str) {} }; +template +struct is_runtime_compiled_format + : std::is_base_of {}; + +template struct is_constexpr_compiled_format : std::false_type {}; + +template struct is_compiled_format { + constexpr static bool value = is_runtime_compiled_format::value || + is_constexpr_compiled_format::value; +}; + #ifdef __cpp_if_constexpr template struct type_list {}; @@ -473,6 +484,13 @@ constexpr auto compile_format_string(S format_str) { format_str); } } + +template +struct is_constexpr_compiled_format> : std::true_type {}; + +template +struct is_constexpr_compiled_format> : std::true_type {}; + #endif // __cpp_if_constexpr } // namespace internal @@ -499,8 +517,8 @@ constexpr auto compile(S format_str) { template ::value)> + FMT_ENABLE_IF( + internal::is_constexpr_compiled_format::value)> std::basic_string format(const CompiledFormat& cf, const Args&... args) { basic_memory_buffer buffer; using range = buffer_range; @@ -510,8 +528,8 @@ std::basic_string format(const CompiledFormat& cf, const Args&... args) { } template ::value)> + FMT_ENABLE_IF( + internal::is_constexpr_compiled_format::value)> OutputIt format_to(OutputIt out, const CompiledFormat& cf, const Args&... args) { return cf.format(out, args...); @@ -533,10 +551,10 @@ auto compile(const Char (&format_str)[N]) basic_string_view(format_str, N - 1)); } -template ::value)> +template < + typename CompiledFormat, typename... Args, + typename Char = typename CompiledFormat::char_type, + FMT_ENABLE_IF(internal::is_runtime_compiled_format::value)> std::basic_string format(const CompiledFormat& cf, const Args&... args) { basic_memory_buffer buffer; using range = buffer_range; @@ -546,9 +564,9 @@ std::basic_string format(const CompiledFormat& cf, const Args&... args) { return to_string(buffer); } -template ::value)> +template < + typename OutputIt, typename CompiledFormat, typename... Args, + FMT_ENABLE_IF(internal::is_runtime_compiled_format::value)> OutputIt format_to(OutputIt out, const CompiledFormat& cf, const Args&... args) { using char_type = typename CompiledFormat::char_type; @@ -558,8 +576,10 @@ OutputIt format_to(OutputIt out, const CompiledFormat& cf, range(out), cf, {make_format_args(args...)}); } -template ::value)> +template < + typename OutputIt, typename CompiledFormat, typename... Args, + FMT_ENABLE_IF(internal::is_output_iterator::value&& + internal::is_compiled_format::value)> format_to_n_result format_to_n(OutputIt out, size_t n, const CompiledFormat& cf, const Args&... args) { @@ -568,7 +588,8 @@ format_to_n_result format_to_n(OutputIt out, size_t n, return {it.base(), it.count()}; } -template +template ::value)> std::size_t formatted_size(const CompiledFormat& cf, const Args&... args) { return format_to( internal::counting_iterator(),