chore: update README for as_* functions

This commit is contained in:
ToruNiina
2019-04-27 16:50:44 +09:00
parent aa7b9a3965
commit 20a13754a7

View File

@@ -500,9 +500,9 @@ You can check what type of value does `toml::value` contains by `is_*` function.
```cpp ```cpp
toml::value v = /* ... */; toml::value v = /* ... */;
if(v.is_integer() && toml::get<int>(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)) // ... 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 ## Visiting a toml::value
toml11 provides `toml::visit` to apply a function to `toml::value` in the toml11 provides `toml::visit` to apply a function to `toml::value` in the