value::at

Access an element, with bounds checking.

Synopsis

value&
at(
    string_view key,
    boost::source_location const& loc = BOOST_CURRENT_LOCATION) &; (1)

value&&
at(
    string_view key,
    boost::source_location const& loc = BOOST_CURRENT_LOCATION) &&; (2)

value const&
at(
    string_view key,
    boost::source_location const& loc = BOOST_CURRENT_LOCATION) const&; (3)

value&
at(
    std::size_t pos,
    boost::source_location const& loc = BOOST_CURRENT_LOCATION) &; (4)

value&&
at(
    std::size_t pos,
    boost::source_location const& loc = BOOST_CURRENT_LOCATION) &&; (5)

value const&
at(
    std::size_t pos,
    boost::source_location const& loc = BOOST_CURRENT_LOCATION) const&; (6)

Description

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

  • (1)(3) is equivalent to this->as_object(loc).at(key, loc).

  • (4)(6) is equivalent to this->as_array(loc).at(pos, loc).

Complexity

Constant.

Exception Safety

Strong guarantee.

Parameters

Name Description

key

The key of the element to find.

loc

boost::source_location to use in thrown exception; the source location of the call site by default.

pos

A zero-based array index.

Exceptions

Type Thrown On

boost::system::system_error

The underlying type of value is not the container type corresponding to the first argument (i.e. using an index with an object).

boost::system::system_error

An element corresponding to the first argument was not found.

See Also