A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/fmtlib/fmt/issues/4261 below:

Is it intentional that the parameter of to_string(basic_memory_buffer<char, SIZE>& buf) is not const? · Issue #4261 · fmtlib/fmt · GitHub

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

  1. declare my member function calling to_string not const as well, which seems like an unnecessary restriction to me
  2. 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?
  3. 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?


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4