-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Description
I'm writing a little helper class, which uses a basic_memory_buffer<char, SIZE> buffer internally and does multiple calls to format_to(std::back_inserter(buffer), fmt, args...) throughout it's lifetime.
Eventually the buffer content is retrieved as a string using the following function:
template <size_t SIZE>
FMT_NODISCARD auto to_string(basic_memory_buffer<char, SIZE>& buf)
-> std::string {
auto size = buf.size();
detail::assume(size < std::string().max_size());
return {buf.data(), size};
}
Since both operations size() and data() are declared const it should be possible to make buf const, doesn't it?
Since the parameter buf is const in my case, it is trying to using the generic overload
template <typename T, FMT_ENABLE_IF(detail::use_format_as<T>::value)>
FMT_NODISCARD auto to_string(const T& value) -> std::string {
return to_string(format_as(value));
}
which then results in a compilation error, stating that "parse" is not a member of "fmt::v11::formatter<T,char,void>".
Therefore I either have to
- declare my member function calling to_string not const as well, which seems like an unnecessary restriction to me
- or use const_cast to force the use of this overload even though it looks like a bad smell to me. Would it be safe to do so anyways?
- or use some other approach that I'm not aware of
As of writing this question I found out that this change was made quite recently with the commit
ab8f9d5?
Metadata
Metadata
Assignees
Labels
No labels