ListInsertR
Description
Insert a single element at the given index. R-value form: source is treated as a temporary value and is never zeroed.
Parameters
| Name | Direction | Description |
|---|---|---|
l |
in,out | List handle. |
rval |
in | Value to insert. |
idx |
in | Position in [0, length]. |
Success
Returns true. A new node holding a copy of rval is linked at position idx; the list length grows by one. The source expression is untouched.
Failure
Returns false on allocation failure. The list is unchanged.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
ListInt.c:69:
if (idx <= ListLen(list)) {
ListInsertR(list, value, idx);
}
break;- In
List.Insert.c:62:
ListInsertL(&list, a, 0);
ListInsertR(&list, b, 1);
ListInsert(&list, c, 1);
ListPushFrontL(&list, d);
static bool test_list_insert_out_of_range_fails(void) {
WriteFmt("Testing ListInsertR out of range\n");
List(int) list = ListInit(get_test_alloc());
List(int) list = ListInit(get_test_alloc());
ListInsertR(&list, 10, 1);
return false;- In
Insert.h:99:
/// TAGS: List, PushFront, RValue
///
#define ListPushFrontR(l, rval) ListInsertR((l), (rval), 0)
///
- In
Insert.h:141:
/// TAGS: List, PushBack, RValue
///
#define ListPushBackR(l, rval) ListInsertR((l), (rval), (l)->length)
///
- In
Insert.h:312:
#define ListMustInsertR(l, rval, idx) \
do { \
if (!ListInsertR((l), (rval), (idx))) { \
LOG_FATAL("ListMustInsertR failed"); \
} \
Last updated on