Skip to content

Commit 26c6b1c

Browse files
committed
Move copy to format.h
1 parent b2a96c6 commit 26c6b1c

File tree

4 files changed

+70
-69
lines changed

4 files changed

+70
-69
lines changed

include/fmt/base.h

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,64 +2031,6 @@ template <typename T = char> class counting_buffer : public buffer<T> {
20312031
template <typename T>
20322032
struct is_back_insert_iterator<basic_appender<T>> : std::true_type {};
20332033

2034-
template <typename OutputIt, typename InputIt, typename = void>
2035-
struct has_back_insert_iterator_container_append : std::false_type {};
2036-
template <typename OutputIt, typename InputIt>
2037-
struct has_back_insert_iterator_container_append<
2038-
OutputIt, InputIt,
2039-
void_t<decltype(get_container(std::declval<OutputIt>())
2040-
.append(std::declval<InputIt>(),
2041-
std::declval<InputIt>()))>> : std::true_type {};
2042-
2043-
template <typename OutputIt, typename InputIt, typename = void>
2044-
struct has_back_insert_iterator_container_insert_at_end : std::false_type {};
2045-
2046-
template <typename OutputIt, typename InputIt>
2047-
struct has_back_insert_iterator_container_insert_at_end<
2048-
OutputIt, InputIt,
2049-
void_t<decltype(get_container(std::declval<OutputIt>())
2050-
.insert(get_container(std::declval<OutputIt>()).end(),
2051-
std::declval<InputIt>(),
2052-
std::declval<InputIt>()))>> : std::true_type {};
2053-
2054-
// An optimized version of std::copy with the output value type (T).
2055-
template <typename T, typename InputIt, typename OutputIt,
2056-
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value&&
2057-
has_back_insert_iterator_container_append<
2058-
OutputIt, InputIt>::value)>
2059-
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
2060-
get_container(out).append(begin, end);
2061-
return out;
2062-
}
2063-
2064-
template <typename T, typename InputIt, typename OutputIt,
2065-
FMT_ENABLE_IF(is_back_insert_iterator<OutputIt>::value &&
2066-
!has_back_insert_iterator_container_append<
2067-
OutputIt, InputIt>::value &&
2068-
has_back_insert_iterator_container_insert_at_end<
2069-
OutputIt, InputIt>::value)>
2070-
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
2071-
auto& c = get_container(out);
2072-
c.insert(c.end(), begin, end);
2073-
return out;
2074-
}
2075-
2076-
template <typename T, typename InputIt, typename OutputIt,
2077-
FMT_ENABLE_IF(!(is_back_insert_iterator<OutputIt>::value &&
2078-
(has_back_insert_iterator_container_append<
2079-
OutputIt, InputIt>::value ||
2080-
has_back_insert_iterator_container_insert_at_end<
2081-
OutputIt, InputIt>::value)))>
2082-
FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
2083-
while (begin != end) *out++ = static_cast<T>(*begin++);
2084-
return out;
2085-
}
2086-
2087-
template <typename T, typename V, typename OutputIt>
2088-
FMT_CONSTEXPR auto copy(basic_string_view<V> s, OutputIt out) -> OutputIt {
2089-
return copy<T>(s.begin(), s.end(), out);
2090-
}
2091-
20922034
template <typename It, typename Enable = std::true_type>
20932035
struct is_buffer_appender : std::false_type {};
20942036
template <typename It>

include/fmt/format.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
570629
template <typename OutChar, typename InputIt, typename OutputIt>
571630
FMT_CONSTEXPR FMT_NOINLINE auto copy_noinline(InputIt begin, InputIt end,
572631
OutputIt out) -> OutputIt {

test/base-test.cc

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,6 @@ TEST(base_test, is_back_insert_iterator) {
282282
std::front_insert_iterator<std::string>>::value);
283283
}
284284

285-
struct minimal_container {
286-
using value_type = char;
287-
void push_back(char) {}
288-
};
289-
290-
TEST(base_test, copy) {
291-
minimal_container c;
292-
static constexpr char str[] = "a";
293-
fmt::detail::copy<char>(str, str + 1, std::back_inserter(c));
294-
}
295-
296285
TEST(base_test, get_buffer) {
297286
mock_buffer<char> buffer;
298287
void* buffer_ptr = &buffer;

test/format-test.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ TEST(util_test, increment) {
196196
EXPECT_STREQ("200", s);
197197
}
198198

199+
struct minimal_container {
200+
using value_type = char;
201+
void push_back(char) {}
202+
};
203+
204+
TEST(util_test, copy) {
205+
minimal_container c;
206+
static constexpr char str[] = "a";
207+
fmt::detail::copy<char>(str, str + 1, std::back_inserter(c));
208+
}
209+
199210
TEST(util_test, parse_nonnegative_int) {
200211
auto s = fmt::string_view("10000000000");
201212
auto begin = s.begin(), end = s.end();

0 commit comments

Comments
 (0)