Export compiled_string so that user can customize one - #3999
Conversation
|
Thanks for the PR. Could you elaborate what you mean by customizing a compile string? |
|
Hi, I would like to do something like the following: template <size_t N> struct FixedString {
constexpr inline FixedString(const char (&str)[N]) {
std::copy_n(str, N, data);
}
constexpr inline FixedString() {}
char data[N] = {};
};
template <FixedString Str>
struct CompiledString : fmt::detail::compiled_string {
using char_type = char;
explicit constexpr inline operator fmt::basic_string_view<char_type>() const {
return {Str.data, sizeof(Str.data) - 1};
}
};
template <FixedString Str, typename... T>
constexpr inline void LOG(T &&...args)
{
std::array<char, 1024> buf{};
auto s = fmt::format_to_n(buf.data(), buf.size(), CompiledString<Str>{},
std::forward<T>(args)...)
.size;
buf[s] = '\0';
write_log(buf.data());
}
LOG<"hello {}">("world");Since there's a |
|
I think it would be better to move |
|
@vitaut In fact, I aslo want to add |
vitaut
left a comment
There was a problem hiding this comment.
The use case makes sense but let's move it to the public namespace (fmt) then.
64cf1fd to
b562d03
Compare
|
Merged, thanks! |
No description provided.