VecInsertFastR
Description
Insert a single element using fast (order-not-preserving) placement. R-value form: the source is treated as a temporary value.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in,out | Vector handle. |
rval |
in | Value to insert. |
idx |
in | Position in [0, length]. |
Success
Returns true. The vector length grows by one. The element that previously sat at idx now sits at the new tail; rval’s value occupies idx.
Failure
Returns false on allocation failure. The vector is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
// Use a temporary variable to avoid r-value issues
int temp = 99;
VecInsertFastR(&vec, temp, 2);
// Check vector length
// Try inserting just one element first with fast insert
int single_val = 42;
VecInsertFastR(&vec2, single_val, 2);
result = result && (VecLen(&vec2) == 6);- In
Vec.Insert.c:397:
// Test R-value fast insert
VecInsertFastR(&vec, LVAL(60), 1);
// Check that the element was inserted
- In
Insert.h:622:
#define VecMustInsertFastR(v, rval, idx) \
do { \
if (!VecInsertFastR((v), (rval), (idx))) { \
LOG_FATAL("VecMustInsertFastR failed"); \
} \- In
Insert.h:452:
/// TAGS: Str, Insert, Char, RValue, Fast, Unordered
///
#define StrInsertFastR(str, rval, idx) VecInsertFastR((str), (rval), (idx))
///
Last updated on