From 20a13754a77254a524ed21215333fb14c9da7726 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sat, 27 Apr 2019 16:50:44 +0900 Subject: [PATCH] chore: update README for as_* functions --- README.md | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e8ea0a6..fc8c8db 100644 --- a/README.md +++ b/README.md @@ -500,9 +500,9 @@ You can check what type of value does `toml::value` contains by `is_*` function. ```cpp toml::value v = /* ... */; -if(v.is_integer() && toml::get(v) == 42) +if(v.is_integer()) { - std::cout << "value is 42" << std::endl; + std::cout << "value is an integer" << std::endl; } ``` @@ -546,6 +546,36 @@ toml::value v = /* ... */; if(v.is(toml::value_t::Boolean)) // ... ``` +## Casting value + +So far, `toml::get` is introduced, but if you don't need any type conversion, +`as_*` is simpler to use. + +```cpp +toml::value v = /* ... */; +if(v.is_integer() && v.as_integer() == 42) +{ + std::cout << "value is 42" << std::endl; +} +``` + +The complete list of the functions is below. + +```cpp +const toml::value v(/*...*/); +v.as_boolean(); +v.as_integer(); +v.as_float(); +v.as_string(); +v.as_offset_datetime(); +v.as_local_datetime(); +v.as_local_date(); +v.as_local_time(); +v.as_array(); +v.as_table(); +v.as_uninitialized(); +``` + ## Visiting a toml::value toml11 provides `toml::visit` to apply a function to `toml::value` in the