ListInsertL

Table of Contents

ListInsertL

Description

Insert an l-value into list of it’s type. Insertion index must not exceed list length.

Info

If copy_init is set, then vector will create it’s own copy of items. If copy_init is not set, then provided l-value will be memset to 0 to keep unique ownership.

Note

Ownership of item is transferred to list if no copy_init method is set. This is to prevent multiple ownership of same object, once inserted into list. Object may not be usable after this call if copy_init is not set.

Parameters

NameDirectionDescription
lin,outList to insert item into
lvalinl-value to be inserted
idxinIndex to insert item at.

Usage example (from documentation)

  // the data
  int x = 10;
  int y = 20;

  // vector
  List(int) integers = ListInit();

  // insert items
  ListInsertL(&integers, x, 0); // x = 0 now, unlike x = 10 in ListInsertR
  ListInsertL(&integers, y, 0); // y = 0 now, unlike y = 20 in ListInsertR
  ListInsertL(&integers, LVAL(101), 1); // took a r-value, and converted to l-value on spot
  // better use ListInsertR in this last case though, otherwise there'll be an extra useless function call

Success

return

Failure

Does not return

Usage example (Cross-references)

    /// FAILURE: Does not return
    ///
    #define ListInsert(l, lval, idx) ListInsertL((l), (lval), (idx))
    
    ///
    /// FAILURE: Does not return.
    ///
    #define ListPushFrontL(l, lval) ListInsertL((l), (lval), 0);
    
    ///
    /// FAILURE: Does not return
    ///
    #define ListPushBackL(l, lval) ListInsertL((l), (lval), (l)->length)
    
    ///

Share :