Cleanup copy functions and move to base.h
This commit is contained in:
@@ -1123,6 +1123,40 @@ using appender = basic_appender<char>;
|
||||
|
||||
namespace detail {
|
||||
|
||||
// An optimized version of std::copy with the output value type (T).
|
||||
template <typename T, typename InputIt>
|
||||
auto copy(InputIt begin, InputIt end, appender out) -> appender {
|
||||
get_container(out).append(begin, end);
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T, typename InputIt, typename OutputIt,
|
||||
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value)>
|
||||
auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
|
||||
get_container(out).append(begin, end);
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T, typename InputIt, typename OutputIt,
|
||||
FMT_ENABLE_IF(!is_back_insert_iterator<OutputIt>::value)>
|
||||
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
|
||||
while (begin != end) *out++ = static_cast<T>(*begin++);
|
||||
return out;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
FMT_CONSTEXPR auto copy(const T* begin, const T* end, T* out) -> T* {
|
||||
if (is_constant_evaluated()) return copy<T, const T*, T*>(begin, end, out);
|
||||
auto size = to_unsigned(end - begin);
|
||||
if (size > 0) memcpy(out, begin, size * sizeof(T));
|
||||
return out + size;
|
||||
}
|
||||
|
||||
template <typename T, typename V, typename OutputIt>
|
||||
FMT_CONSTEXPR auto copy(basic_string_view<V> s, OutputIt out) -> OutputIt {
|
||||
return copy<T>(s.begin(), s.end(), out);
|
||||
}
|
||||
|
||||
template <typename Context, typename T>
|
||||
constexpr auto has_const_formatter_impl(T*)
|
||||
-> decltype(typename Context::template formatter_type<T>().format(
|
||||
|
||||
Reference in New Issue
Block a user