From e73c98490bd01123f88ed73a2b2f119f3b7d96c4 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sat, 15 May 2021 21:47:03 +0900 Subject: [PATCH] doc: add recursive find_or to README --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 5f5040f..9a8954f 100644 --- a/README.md +++ b/README.md @@ -835,6 +835,19 @@ const auto data = toml::parse("example.toml"); 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` failed. ```cpp