src: Use std::copy_n

This commit is contained in:
Tatsuhiro Tsujikawa 2015-02-06 21:35:03 +09:00
parent b165775811
commit 4956bdc4da
5 changed files with 12 additions and 11 deletions

View File

@ -211,7 +211,7 @@ public:
len = 0;
if (buf_) {
std::copy(buf_, buf_ + buflen_, std::begin(buffer));
std::copy_n(buf_, buflen_, std::begin(buffer));
len += buflen_;
@ -237,7 +237,7 @@ public:
break;
}
std::copy(data, data + nread, std::begin(buffer) + len);
std::copy_n(data, nread, std::begin(buffer) + len);
len += nread;
}

View File

@ -44,7 +44,7 @@ template <size_t N> struct Buffer {
size_t write(const void *src, size_t count) {
count = std::min(count, wleft());
auto p = static_cast<const uint8_t *>(src);
last = std::copy(p, p + count, last);
last = std::copy_n(p, count, last);
return count;
}
size_t write(size_t count) {

View File

@ -1204,8 +1204,8 @@ int main(int argc, char **argv) {
auto proto_list = util::get_default_alpn();
#ifdef HAVE_SPDYLAY
static const char spdy_proto_list[] = "\x8spdy/3.1\x6spdy/3\x6spdy/2";
std::copy(spdy_proto_list, spdy_proto_list + sizeof(spdy_proto_list) - 1,
std::back_inserter(proto_list));
std::copy_n(spdy_proto_list, sizeof(spdy_proto_list) - 1,
std::back_inserter(proto_list));
#endif // HAVE_SPDYLAY
SSL_CTX_set_alpn_protos(ssl_ctx, proto_list.data(), proto_list.size());
#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L

View File

@ -33,6 +33,7 @@
#include <cstring>
#include <memory>
#include <array>
#include <algorithm>
#include "template.h"
@ -134,7 +135,7 @@ template <typename Memchunk> struct Memchunks {
for (;;) {
auto n = std::min(static_cast<size_t>(last - first), tail->left());
tail->last = std::copy(first, first + n, tail->last);
tail->last = std::copy_n(first, n, tail->last);
first += n;
len += n;
if (first == last) {
@ -165,7 +166,7 @@ template <typename Memchunk> struct Memchunks {
auto n = std::min(static_cast<size_t>(last - first), m->len());
assert(m->len());
first = std::copy(m->pos, m->pos + n, first);
first = std::copy_n(m->pos, n, first);
m->pos += n;
len -= n;
if (m->len() > 0) {

View File

@ -195,13 +195,13 @@ std::string http_date(time_t t) {
auto p = std::begin(res);
auto s = DAY_OF_WEEK[tms.tm_wday];
p = std::copy(s, s + 3, p);
p = std::copy_n(s, 3, p);
*p++ = ',';
*p++ = ' ';
p = cpydig(p, tms.tm_mday, 2);
*p++ = ' ';
s = MONTH[tms.tm_mon];
p = std::copy(s, s + 3, p);
p = std::copy_n(s, 3, p);
*p++ = ' ';
p = cpydig(p, tms.tm_year + 1900, 4);
*p++ = ' ';
@ -211,7 +211,7 @@ std::string http_date(time_t t) {
*p++ = ':';
p = cpydig(p, tms.tm_sec, 2);
s = " GMT";
p = std::copy(s, s + 4, p);
p = std::copy_n(s, 4, p);
return res;
}
@ -234,7 +234,7 @@ std::string common_log_date(time_t t) {
p = cpydig(p, tms.tm_mday, 2);
*p++ = '/';
auto s = MONTH[tms.tm_mon];
p = std::copy(s, s + 3, p);
p = std::copy_n(s, 3, p);
*p++ = '/';
p = cpydig(p, tms.tm_year + 1900, 4);
*p++ = ':';