diff --git a/ostd/range.hh b/ostd/range.hh index 5868b1b..7a5c555 100644 --- a/ostd/range.hh +++ b/ostd/range.hh @@ -477,12 +477,13 @@ template>> - Size copy(OR &&orange, Size n = -1) { + template + EnableIf, Size> copy(OR &&orange, Size n = -1) { B r(*((B *)this)); Size on = n; for (; n && !r.empty(); --n) { - orange.put(r.front()); + if (!orange.put(r.front())) + break; r.pop_front(); } return (on - n); @@ -984,8 +985,8 @@ public: return ret; } - template>> - Size copy(R &&orange, Size n = -1) { + template + EnableIf, Size> copy(R &&orange, Size n = -1) { Size c = size(); if (n < c) c = n; return orange.put_n(p_beg, c); @@ -994,6 +995,10 @@ public: Size copy(RemoveCv *p, Size n = -1) { Size c = size(); if (n < c) c = n; + if (IsPod) { + memcpy(p_beg, data(), c * sizeof(T)); + return c; + } return copy(PointerRange(p, c), c); } diff --git a/ostd/string.hh b/ostd/string.hh index b22fe2f..b69b299 100644 --- a/ostd/string.hh +++ b/ostd/string.hh @@ -145,6 +145,13 @@ public: return true; } + Size put_n(const T *p, Size n) { + Size an = ostd::min(n, size()); + memcpy(p_beg, p, an * sizeof(T)); + p_beg += an; + return an; + } + T *data() { return p_beg; } const T *data() const { return p_beg; }