From aa6271af75233d05b5b421b3a764240b170c5c2d Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 9 Jan 2020 01:40:05 +0900 Subject: [PATCH] doc: update README --- README.md | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 37b75d0..4a0c52d 100644 --- a/README.md +++ b/README.md @@ -274,10 +274,31 @@ const auto color = toml::find(data, "fruit", "physical", "color"); const auto shape = toml::find(data, "fruit", "physical", "shape"); ``` +### Finding a value in an array + +You can find n-th value in an array by `toml::find`. + +```toml +values = ["foo", "bar", "baz"] +``` + +``` cpp +const auto data = toml::parse("sample.toml"); +const auto values = toml::find(data, "values"); +const auto bar = toml::find(values, 1); +``` + +`toml::find` can also search array recursively. + +```cpp +const auto data = toml::parse("fruit.toml"); +const auto bar = toml::find(data, "values", 1); +``` + ### In case of error -If the value does not exist, `toml::find` throws an error with the location of -the table. +If the value does not exist, `toml::find` throws `std::out_of_range` with the +location of the table. ```console terminate called after throwing an instance of 'std::out_of_range' @@ -287,11 +308,6 @@ terminate called after throwing an instance of 'std::out_of_range' | ~~~~~ in this table ``` -**Note**: It is recommended to find a table as `toml::value` because it has much information -compared to `toml::table`, which is an alias of -`std::unordered_map`. Since `toml::table` does not have -any information about toml file, such as where the table was defined in the file. - ---- If the specified type differs from the actual value contained, it throws