Allow fmt::compile to accept a fmt::basic_string_view in addition to a string literal.

This commit is contained in:
Dair Grant 2020-03-07 00:17:25 +00:00
parent 50f1131fba
commit d94558359a

View File

@ -542,7 +542,7 @@ constexpr auto compile(S format_str) -> internal::compiled_format<S, Args...> {
# endif // __cpp_if_constexpr
#endif // FMT_USE_CONSTEXPR
// Compiles the format string which must be a string literal.
// Compiles the format string which must be a string literal or view.
template <typename... Args, typename Char, size_t N>
auto compile(const Char (&format_str)[N])
-> internal::compiled_format<const Char*, Args...> {
@ -550,6 +550,13 @@ auto compile(const Char (&format_str)[N])
basic_string_view<Char>(format_str, N - 1));
}
template <typename Char>
auto compile(const basic_string_view<Char>& format_str)
-> internal::compiled_format<const Char*> {
return internal::compiled_format<const Char*>(
format_str);
}
template <typename CompiledFormat, typename... Args,
typename Char = typename CompiledFormat::char_type,
FMT_ENABLE_IF(std::is_base_of<internal::basic_compiled_format,