reserve(std::max(other.len, n)); std::copy(other.buf, other.buf + other.used, buf); used = other.used; } void String::about_to_modify(size_t n, bool unshareable /* = false */) { if (data->refs > 1 && data->refs != UNSHAREABLE) { StringBuf *newdata = new StringBuf(*data, n); --data->refs; data = newdata; } else data->reserve(n); data->refs = unshareable ? UNSHAREABLE : 1; } char &String::operator[](size_t n) { about_to_modify(data->len, true); return *(data->buf+n); }