Restrict fmt::compile to literal strings

to make sure we don't break the API too much when making all of this
compile-time only.
This commit is contained in:
Victor Zverovich
2019-08-10 13:18:11 -07:00
parent 544b537334
commit e8219952c6
2 changed files with 13 additions and 184 deletions
+13 -27
View File
@@ -613,44 +613,30 @@ template <typename... Args>
using prepared_format_t =
typename basic_prepared_format<std::string, parts_container<char>,
Args...>::type;
} // namespace internal
#if FMT_USE_CONSTEXPR
template <typename... Args, typename S>
FMT_CONSTEXPR auto compile(S format_str) {
return internal::do_compile<S, Args...>(
typename internal::format_tag<S>::type{}, std::move(format_str));
}
#else
template <typename... Args, typename S>
auto compile(S format_str) ->
typename internal::preparator<S, Args...>::prepared_format_type {
return internal::preparator<S, Args...>::prepare(std::move(format_str));
}
} // namespace internal
#if FMT_USE_CONSTEXPR
template <typename... Args, typename S,
FMT_ENABLE_IF(is_compile_string<S>::value)>
FMT_CONSTEXPR auto compile(S format_str) {
return internal::do_compile<S, Args...>(
typename internal::format_tag<S>::type{}, std::move(format_str));
}
#endif
template <typename... Args, typename Char>
auto compile(const Char* format_str) ->
typename internal::preparator<std::basic_string<Char>,
Args...>::prepared_format_type {
return compile<Args...>(internal::to_runtime_format(format_str));
}
template <typename... Args, typename Char, unsigned N>
auto compile(const Char(format_str)[N]) ->
auto compile(const Char (&format_str)[N]) ->
typename internal::preparator<std::basic_string<Char>,
Args...>::prepared_format_type {
const auto view = basic_string_view<Char>(format_str, N);
return compile<Args...>(internal::to_runtime_format(view));
}
template <typename... Args, typename Char>
auto compile(basic_string_view<Char> format_str) ->
typename internal::preparator<std::basic_string<Char>,
Args...>::prepared_format_type {
return compile<Args...>(internal::to_runtime_format(format_str));
const auto view = basic_string_view<Char>(format_str, N - 1);
return internal::compile<Args...>(internal::to_runtime_format(view));
}
template <typename CompiledFormat, typename... Args,