mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-18 02:08:09 +08:00
doc: update README
This commit is contained in:
30
README.md
30
README.md
@@ -274,10 +274,31 @@ const auto color = toml::find<std::string>(data, "fruit", "physical", "color");
|
|||||||
const auto shape = toml::find<std::string>(data, "fruit", "physical", "shape");
|
const auto shape = toml::find<std::string>(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<std::string>(values, 1);
|
||||||
|
```
|
||||||
|
|
||||||
|
`toml::find` can also search array recursively.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
const auto data = toml::parse("fruit.toml");
|
||||||
|
const auto bar = toml::find<std::string>(data, "values", 1);
|
||||||
|
```
|
||||||
|
|
||||||
### In case of error
|
### In case of error
|
||||||
|
|
||||||
If the value does not exist, `toml::find` throws an error with the location of
|
If the value does not exist, `toml::find` throws `std::out_of_range` with the
|
||||||
the table.
|
location of the table.
|
||||||
|
|
||||||
```console
|
```console
|
||||||
terminate called after throwing an instance of 'std::out_of_range'
|
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
|
| ~~~~~ 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<std::string, toml::value>`. 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
|
If the specified type differs from the actual value contained, it throws
|
||||||
|
Reference in New Issue
Block a user