mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-09 22:30:07 +00:00
doc: add recursive find_or to README
This commit is contained in:
parent
7b9a1abdb3
commit
e73c98490b
13
README.md
13
README.md
@ -835,6 +835,19 @@ const auto data = toml::parse("example.toml");
|
|||||||
const auto num = toml::find_or(data, "num", 42);
|
const auto num = toml::find_or(data, "num", 42);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
It works recursively if you pass several keys for subtables.
|
||||||
|
In that case, the last argument is considered to be the optional value.
|
||||||
|
All other arguments between `toml::value` and the optinoal value are considered as keys.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// [fruit.physical]
|
||||||
|
// color = "red"
|
||||||
|
auto data = toml::parse("fruit.toml");
|
||||||
|
auto color = toml::find_or(data, "fruit", "physical", "color", "red");
|
||||||
|
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
|
||||||
|
// arguments optional value
|
||||||
|
```
|
||||||
|
|
||||||
Also, `toml::get_or` returns a default value if `toml::get<T>` failed.
|
Also, `toml::get_or` returns a default value if `toml::get<T>` failed.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
|
Loading…
Reference in New Issue
Block a user