From 436af12815d3500f7888dc2380aa7fe314aeece4 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 7 Jun 2019 19:43:01 +0900 Subject: [PATCH] doc: update README --- README.md | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index d96c15a..ee3bd99 100644 --- a/README.md +++ b/README.md @@ -573,29 +573,49 @@ if(v.is_integer() && v.as_integer() == 42) } ``` -The complete list of the functions is below. +`as_*` functions internally checks the current contained type for safety and +throws `toml::type_error` if the contained value type is different (after toml11 +v2.4.0). If you already confirmed that the value has the type you will cast +into, you can skip the additional checking by passing `std::nothrow` object to it. + +```cpp +toml::value v = /* ... */; +if(v.is_integer() && v.as_integer(std::nothrow) == 42) // never fail +{ + std::cout << "value is 42" << std::endl; +} +``` + +The full list of the functions is below. ```cpp namespace toml { class value { // ... - const boolean& as_boolean() const& noexcept; - const integer& as_integer() const& noexcept; - const floating& as_floating() const& noexcept; - const string& as_string() const& noexcept; - const offset_datetime& as_offset_datetime() const& noexcept; - const local_datetime& as_local_datetime() const& noexcept; - const local_date& as_local_date() const& noexcept; - const local_time& as_local_time() const& noexcept; - const array& as_array() const& noexcept; - const table& as_table() const& noexcept; + const boolean& as_boolean() const&; + const integer& as_integer() const&; + const floating& as_floating() const&; + const string& as_string() const&; + const offset_datetime& as_offset_datetime() const&; + const local_datetime& as_local_datetime() const&; + const local_date& as_local_date() const&; + const local_time& as_local_time() const&; + const array& as_array() const&; + const table& as_table() const&; // -------------------------------------------------------- // non-const version - boolean& as_boolean() & noexcept; + boolean& as_boolean() &; // ditto... // -------------------------------------------------------- // rvalue version - boolean&& as_boolean() && noexcept; + boolean&& as_boolean() &&; + // ditto... + + // -------------------------------------------------------- + // noexcept versions ... + const boolean& as_boolean(const std::nothrow_t&) const& noexcept; + boolean& as_boolean(const std::nothrow_t&) & noexcept; + boolean&& as_boolean(const std::nothrow_t&) && noexcept; // ditto... }; } // toml