array::if_contains
Return a pointer to an element if it exists.
Synopsis
value const*
if_contains(
std::size_t pos) const noexcept; (1)
value*
if_contains(
std::size_t pos) noexcept; (2)
Description
This function returns a pointer to the element at index pos
when the index is less then the size of the container. Otherwise it returns null.
Example
if( auto p = arr.if_contains( 1 ) )
std::cout << *p;
Complexity
Constant.
Exception Safety
No-throw guarantee.
Parameters
Name | Description |
---|---|
|
The index of the element to return. |