| 322 | } |
| 323 | |
| 324 | Error Array::insert(int p_pos, const Variant &p_value) { |
| 325 | ERR_FAIL_COND_V_MSG(_p->read_only, ERR_LOCKED, "Array is in read-only state."); |
| 326 | Variant value = p_value; |
| 327 | ERR_FAIL_COND_V(!_p->typed.validate(value, "insert"), ERR_INVALID_PARAMETER); |
| 328 | |
| 329 | if (p_pos < 0) { |
| 330 | // Relative offset from the end. |
| 331 | p_pos = _p->array.size() + p_pos; |
| 332 | } |
| 333 | |
| 334 | ERR_FAIL_INDEX_V_MSG(p_pos, _p->array.size() + 1, ERR_INVALID_PARAMETER, vformat("The calculated index %d is out of bounds (the array has %d elements). Leaving the array untouched.", p_pos, _p->array.size())); |
| 335 | |
| 336 | return _p->array.insert(p_pos, std::move(value)); |
| 337 | } |
| 338 | |
| 339 | void Array::fill(const Variant &p_value) { |
| 340 | ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state."); |