value::try_at

Access an element, with bounds checking.

Synopsis

boost::system::result< value & >
try_at(
    string_view key) noexcept; (1)

boost::system::result< value const & >
try_at(
    string_view key) const noexcept; (2)

boost::system::result< value & >
try_at(
    std::size_t pos) noexcept; (3)

boost::system::result< value const & >
try_at(
    std::size_t pos) const noexcept; (4)

Description

Returns boost::system::result containing a reference to the element of the underlying ccontainer, if such element exists. If the underlying value is not a container of the suitable type or the container doesn’t have a corresponding element the result contains an error_code.

, if pos is within its range. If pos is outside of that range, or the underlying value is not an object the

Returns boost::system::result containing a reference to the element of the underlying array, if pos is within its range. If pos is outside of that range, or the underlying value is not an array the result contains an error_code.

This function is used to access elements of the underlying container, or throw an exception if that could not be done.

  • (1), (2) require the underlying container to be an object, and look for an element with the key key.

  • (3), (4) require the underlying container to be an array, and look for an element at index pos.

Exception Safety

No-throw guarantee.

Parameters

Name Description

key

The key of the element to find.

pos

A zero-based array index.

Complexity

Constant.

Exception Safety

No-throw guarantee.