at {cppcontainers} | R Documentation |
Access elements with bounds checking
Description
Read a value at a certain position with bounds checking.
Usage
at(x, position)
Arguments
x |
A CppMap, CppUnorderedMap, CppVector, or CppDeque object. |
position |
A key (CppMap, CppUnorderedMap) or index (CppVector, CppDeque). |
Details
In the two associative container types (CppMap, CppUnorderedMap), []
accesses a value by its key. If the key does not exist, the
function throws an error.
In the two sequence container types (CppVector, CppDeque), []
accesses a value by its index. If the index is outside the container, this throws
an error.
at and []
both access elements. Unlike []
, at checks the bounds of the container and throws an error, if the element does
not exist.
Value
Returns the value at the position.
See Also
[, back, contains, front, top.
Examples
m <- cpp_map(4:6, seq.int(0, 1, by = 0.5))
m
# [4,0] [5,0.5] [6,1]
at(m, 4L)
# [1] 0
d <- cpp_deque(c("hello", "world"))
d
# "hello" "world"
at(d, 2)
# [1] "world"
[Package cppcontainers version 1.0.0 Index]