doc: update README

This commit is contained in:
ToruNiina 2019-07-13 15:11:01 +09:00
parent 87e0ba201e
commit 2eb2e0a753

View File

@ -19,9 +19,6 @@ Not only the test suite itself, a TOML reader/encoder also runs on [CircleCI](ht
You can see the error messages about invalid files and serialization results of valid files at You can see the error messages about invalid files and serialization results of valid files at
[CircleCI](https://circleci.com/gh/ToruNiina/toml11). [CircleCI](https://circleci.com/gh/ToruNiina/toml11).
Now the master branch is showing a beta version of the version 3.
It has some breaking changes from v2. Please be careful.
## Example ## Example
```cpp ```cpp
@ -110,13 +107,13 @@ const toml::table data = toml::parse(fname);
If it encounters an error while opening a file, it will throw `std::runtime_error`. If it encounters an error while opening a file, it will throw `std::runtime_error`.
You can also pass a `std::istream` to the `toml::parse` function. You can also pass a `std::istream` to the `toml::parse` function.
To show a filename in an error message, it is recommended to pass the filename To show a filename in an error message, however, it is recommended to pass the
with the stream. filename with the stream.
```cpp ```cpp
std::ifstream ifs("sample.toml", std::ios_base::binary); std::ifstream ifs("sample.toml", std::ios_base::binary);
assert(ifs.good()); assert(ifs.good());
const auto data = toml::parse(ifs, /*optional*/ "sample.toml"); const auto data = toml::parse(ifs, /*optional -> */ "sample.toml");
``` ```
**Note**: When you are **on Windows, open a file in binary mode**. **Note**: When you are **on Windows, open a file in binary mode**.
@ -268,7 +265,6 @@ const int a = toml::find<int>(data, "answer", "to", "the", "ultimate", "question
``` ```
Of course, alternatively, you can call `toml::find` as many as you need. Of course, alternatively, you can call `toml::find` as many as you need.
But it is a bother.
### In the case of type error ### In the case of type error
@ -320,7 +316,7 @@ const auto color = toml::find<std::string>(physical, "color");
The following code does not work for the above toml file. The following code does not work for the above toml file.
```cpp ```cpp
const auto color = toml::find<std::string>(data, "physical.color"); const auto color = toml::find<std::string>(data, "physical.color"); // does not work
``` ```
The above code works with the following toml file. The above code works with the following toml file.
@ -912,10 +908,17 @@ const auto data = toml::parse<
>("example.toml"); >("example.toml");
``` ```
__NOTE__: Needless to say, the result types from `toml::parse(...)` and Needless to say, the result types from `toml::parse(...)` and
`toml::parse<Com, Map, Cont>(...)` are different (unless you specify the same `toml::parse<Com, Map, Cont>(...)` are different (unless you specify the same
types as default). types as default).
Note that, since `toml::table` and `toml::array` is an alias for a table and an
array of a default `toml::value`, so it is different from the types actually
contained in a `toml::basic_value` when you customize containers.
To get the actual type in a generic way, use
`typename toml::basic_type<C, T, A>::table_type` and
`typename toml::basic_type<C, T, A>::array_type`.
## TOML literal ## TOML literal
toml11 supports `"..."_toml` literal. toml11 supports `"..."_toml` literal.
@ -948,7 +951,6 @@ inline namespace literals
inline namespace toml_literals inline namespace toml_literals
{ {
toml::value operator"" _toml(const char* str, std::size_t len); toml::value operator"" _toml(const char* str, std::size_t len);
} // toml_literals } // toml_literals
} // literals } // literals
} // toml } // toml