diff --git a/docs/content.en/docs/reference/value.md b/docs/content.en/docs/reference/value.md index 9d0fe42..5b1b37c 100644 --- a/docs/content.en/docs/reference/value.md +++ b/docs/content.en/docs/reference/value.md @@ -585,6 +585,27 @@ Throws `std::out_of_range` if the `table` does not contain the specified element ----- +### `try_at(key)` + +```cpp +result, error_info> try_at(const key_type& key) noexcept; +result, error_info> try_at(const key_type& key) const noexcept; +``` + +#### Return Value + +After casting the current `value` to a `table`, it returns the element specified by the `key`. + +If successful, it returns a `reference_wrapper` holding a reference to that element. + +If unsuccessful, it returns an `error_info` corresponding to `type_error` or `out_of_range`. + +#### Exceptions + +Does not throw. + +----- + #### `operator[](key)` ```cpp @@ -652,6 +673,26 @@ Throws `toml::type_error` if the stored value is not an `array`. Throws `std::out_of_range` if the specified element does not exist in the `array`. +----- + +### `try_at(idx)` + +```cpp +result, error_info> try_at(const std::size_t idx) noexcept; +result, error_info> try_at(const std::size_t idx) const noexcept; +``` + +#### Return Value + +After casting the current `value` to an `array`, it returns the element specified by the `idx`. + +If successful, it returns a `reference_wrapper` holding a reference to that element. + +If unsuccessful, it returns an `error_info` corresponding to `type_error` or `out_of_range`. + +#### Exceptions + +Does not throw. ----- diff --git a/docs/content.ja/docs/reference/value.md b/docs/content.ja/docs/reference/value.md index 99853f9..fb5c8cc 100644 --- a/docs/content.ja/docs/reference/value.md +++ b/docs/content.ja/docs/reference/value.md @@ -583,6 +583,27 @@ value_type const& at(const key_type& key) const; ----- +### `try_at(key)` + +```cpp +result, error_info> try_at(const key_type& key) noexcept; +result, error_info> try_at(const key_type& key) const noexcept; +``` + +#### 戻り値 + +今の`value`を`table`にキャストしたあと、`key`によって指定される要素を返します。 + +成功した場合、その要素への参照を持つ`reference_wrapper`を返します。 + +失敗した場合、 `type_error` または `out_of_range` に対応する `error_info` を返します。 + +#### 例外 + +投げません。 + +----- + #### `operator[](key)` ```cpp @@ -652,6 +673,27 @@ value_type const& at(const std::size_t idx) const; ----- +### `try_at(idx)` + +```cpp +result, error_info> try_at(const std::size_t idx) noexcept; +result, error_info> try_at(const std::size_t idx) const noexcept; +``` + +#### 戻り値 + +今の`value`を`array`にキャストしたあと、`idx`によって指定される要素を返します。 + +成功した場合、その要素への参照を持つ`reference_wrapper`を返します。 + +失敗した場合、 `type_error` または `out_of_range` に対応する `error_info` を返します。 + +#### 例外 + +投げません。 + +----- + ### `operator[](idx)` ```cpp