@@ -567,6 +567,65 @@ FMT_CONSTEXPR20 auto fill_n(T* out, Size count, char value) -> T* {
567567 return out + count;
568568}
569569
570+ template <typename OutputIt, typename InputIt, typename = void >
571+ struct has_back_insert_iterator_container_append : std::false_type {};
572+
573+ template <typename OutputIt, typename InputIt>
574+ struct has_back_insert_iterator_container_append <
575+ OutputIt, InputIt,
576+ void_t <decltype (get_container(std::declval<OutputIt>())
577+ .append(std::declval<InputIt>(),
578+ std::declval<InputIt>()))>> : std::true_type {};
579+
580+ template <typename OutputIt, typename InputIt, typename = void >
581+ struct has_back_insert_iterator_container_insert_at_end : std::false_type {};
582+
583+ template <typename OutputIt, typename InputIt>
584+ struct has_back_insert_iterator_container_insert_at_end <
585+ OutputIt, InputIt,
586+ void_t <decltype (get_container(std::declval<OutputIt>())
587+ .insert(get_container(std::declval<OutputIt>()).end(),
588+ std::declval<InputIt>(),
589+ std::declval<InputIt>()))>> : std::true_type {};
590+
591+ // An optimized version of std::copy with the output value type (T).
592+ template <typename T, typename InputIt, typename OutputIt,
593+ FMT_ENABLE_IF (is_back_insert_iterator<OutputIt>::value&&
594+ has_back_insert_iterator_container_append<
595+ OutputIt, InputIt>::value)>
596+ FMT_CONSTEXPR auto copy (InputIt begin, InputIt end, OutputIt out) -> OutputIt {
597+ get_container (out).append (begin, end);
598+ return out;
599+ }
600+
601+ template <typename T, typename InputIt, typename OutputIt,
602+ FMT_ENABLE_IF (is_back_insert_iterator<OutputIt>::value &&
603+ !has_back_insert_iterator_container_append<
604+ OutputIt, InputIt>::value &&
605+ has_back_insert_iterator_container_insert_at_end<
606+ OutputIt, InputIt>::value)>
607+ FMT_CONSTEXPR auto copy (InputIt begin, InputIt end, OutputIt out) -> OutputIt {
608+ auto & c = get_container (out);
609+ c.insert (c.end (), begin, end);
610+ return out;
611+ }
612+
613+ template <typename T, typename InputIt, typename OutputIt,
614+ FMT_ENABLE_IF (!(is_back_insert_iterator<OutputIt>::value &&
615+ (has_back_insert_iterator_container_append<
616+ OutputIt, InputIt>::value ||
617+ has_back_insert_iterator_container_insert_at_end<
618+ OutputIt, InputIt>::value)))>
619+ FMT_CONSTEXPR auto copy (InputIt begin, InputIt end, OutputIt out) -> OutputIt {
620+ while (begin != end) *out++ = static_cast <T>(*begin++);
621+ return out;
622+ }
623+
624+ template <typename T, typename V, typename OutputIt>
625+ FMT_CONSTEXPR auto copy (basic_string_view<V> s, OutputIt out) -> OutputIt {
626+ return copy<T>(s.begin (), s.end (), out);
627+ }
628+
570629template <typename OutChar, typename InputIt, typename OutputIt>
571630FMT_CONSTEXPR FMT_NOINLINE auto copy_noinline (InputIt begin, InputIt end,
572631 OutputIt out) -> OutputIt {
0 commit comments