-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.