doc: add recursive find_or to README

This commit is contained in:
ToruNiina 2021-05-15 21:47:03 +09:00
parent 7b9a1abdb3
commit e73c98490b

View File

@ -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