insert {cppcontainers}R Documentation

Add elements

Description

Add elements to a container by reference.

Usage

insert(x, values, keys = NULL, position = NULL)

Arguments

x

A CppSet, CppUnorderedSet, CppMultiset, CppUnorderedMultiset, CppMap, CppUnorderedMap, CppMultimap, CppUnorderedMultimap, CppVector, CppDeque, or CppList object.

values

Values to add to x.

keys

Keys to add to x. Only relevant for CppMap, CppUnorderedMap, CppMultimap, and CppUnorderedMultimap objects.

position

Index at which to insert elements into x. Only relevant for CppVector, CppDeque, and CppList objects. Indices start at 1.

Details

Existing container values are not overwritten. I.e. inserting a key-value pair into a map that already contains that key preserves the old value and discards the new one. Use insert_or_assign to overwrite values.

Value

Invisibly returns NULL.

See Also

assign, emplace, insert_after, insert_or_assign, push.

Examples

s <- cpp_multiset(4:6)
s
# 4 5 6

insert(s, 6:7)
s
# 4 5 6 6 7

m <- cpp_map(c("hello", "there", "world"), 9:11)
m
# ["hello",9] ["there",10] ["world",11]

insert(m, 12L, "there")
m
# ["hello",9] ["there",10] ["world",11]


[Package cppcontainers version 1.0.0 Index]