void cv_vector_insert_block(cv_vector hwv, size_t pos, cv_iterator begin, cv_iterator end) { if (cv_vector_empty(hwv)) CV_Error(STS_NULL_PTR, "cv_vector is a null pointer"); // 判断 pos 是否越界 < 0 || > cv_size if (pos < 0 || pos > hwv->cv_size) CV_Error(STS_BAD_ARG, "param is bad"); // 计算新尺寸 size_t new_size = hwv->cv_size + ((char*)end - (char*)begin) / hwv->elem_size; // 计算并调节新容量 while (hwv->cv_capacity < new_size) hwv->cv_capacity <<= EXPANED_VAL; adjust_capacity(hwv, hwv->cv_capacity); // pos 是不是末尾元素 = cv_size if (pos == hwv->cv_size) { memcpy((char*)hwv->data + pos * hwv->elem_size, begin, (char*)end - (char*)begin); } else { cv_iterator src = cv_vector_index_to_iter(hwv, pos); size_t bytes = ((char*)end - (char*)begin); cv_iterator dst = (char*)src + bytes; memmove(dst, src, bytes); memcpy(src, begin, bytes); } // 更新尺寸 hwv->cv_size = new_size; }