Repository: fmtlib/fmt
File: include/fmt/core.h (C/C++)

Code before:
                true) {
  return true;
}
template <typename Context>
constexpr auto is_const_formattable_impl(...) -> bool {
  return false;
}
template <typename T, typename Context>
constexpr auto is_const_formattable() -> bool {
  return is_const_formattable_impl<Context>(static_cast<T*>(nullptr));
}

// Extracts a reference to the container from back_insert_iterator.
template <typename Container>
inline auto get_container(std::back_insert_iterator<Container> it)
    -> Container& {
  using bi_iterator = std::back_insert_iterator<Container>;
  struct accessor : bi_iterator {
    accessor(bi_iterator iter) : bi_iterator(iter) {}
    using bi_iterator::container;
  };
  return *accessor(it).container;
}

template <typename Char, typename InputIt, typename OutputIt>
FMT_CONSTEXPR auto copy_str_constexpr(InputIt begin, InputIt end, OutputIt out)
    -> OutputIt {
  while (begin != end) *out++ = static_cast<Char>(*begin++);
  return out;
}

template <typename Char, typename InputIt, typename OutputIt>
FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out)
    -> OutputIt {
  return copy_str_constexpr<Char>(begin, end, out);
}

template <typename Char, typename InputIt, typename OutputIt>
FMT_CONSTEXPR
typename std::enable_if
<
  std::is_same<typename std::remove_const<InputIt>::type, OutputIt>::value &&
  std::is_trivially_copy_assignable<OutputIt>::value,
  OutputIt*
>::type
copy_str(InputIt* begin, InputIt* end, OutputIt* out)
{
  if (is_constant_evaluated())
    return copy_str_constexpr<Char>(begin, end, out);
  auto size = to_unsigned(end - begin);
  memcpy(out, begin, size * sizeof(OutputIt));

Review comment (suggestion):
I think the proper solution would be to constrain this overload to `InputIt` and `OutputIt` types that are different and both not convertible to `const Char*`.

Code after:
    -> decltype(typename Context::template formatter_type<T>().format(
                    std::declval<const T&>(), std::declval<Context&>()),
                true) {
  return true;
}
template <typename Context>
constexpr auto is_const_formattable_impl(...) -> bool {
  return false;
}
template <typename T, typename Context>
constexpr auto is_const_formattable() -> bool {
  return is_const_formattable_impl<Context>(static_cast<T*>(nullptr));
}

// Extracts a reference to the container from back_insert_iterator.
template <typename Container>
inline auto get_container(std::back_insert_iterator<Container> it)
    -> Container& {
  using bi_iterator = std::back_insert_iterator<Container>;
  struct accessor : bi_iterator {
    accessor(bi_iterator iter) : bi_iterator(iter) {}
    using bi_iterator::container;
  };
  return *accessor(it).container;
}

template <typename Char, typename InputIt, typename OutputIt>
FMT_CONSTEXPR auto copy_str(InputIt begin, InputIt end, OutputIt out)
    -> OutputIt {
  while (begin != end) *out++ = static_cast<Char>(*begin++);
  return out;
}

template <typename Char, typename T, typename U,
FMT_ENABLE_IF(std::is_same<remove_const_t<T>, U>::value && is_char<U>::value)>
FMT_CONSTEXPR auto copy_str(T* begin, T* end, U* out)
    -> U* {
  if (is_constant_evaluated())
    return copy_str<Char, T*, U*>(begin, end, out);
  auto size = to_unsigned(end - begin);
  memcpy(out, begin, size * sizeof(U));
  return out + size;
}

/**
  \rst
  A contiguous memory buffer with an optional growing ability. It is an internal
  class and shouldn't be used directly, only via `~fmt::basic_memory_buffer`.
  \endrst
 */
template <typename T> class buffer {