mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 00:38:08 +08:00
doc: add TOML11_PRESERVE_COMMENTS_BY_DEFAULT
This commit is contained in:
17
README.md
17
README.md
@@ -971,13 +971,28 @@ v.push_back(6);
|
|||||||
|
|
||||||
## Preserving comments
|
## Preserving comments
|
||||||
|
|
||||||
After toml11 v3, you can choose whether comments are preserved or not.
|
toml11 v3 or later allows you yo choose whether comments are preserved or not via template parameter
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
const auto data1 = toml::parse<toml::discard_comments >("example.toml");
|
const auto data1 = toml::parse<toml::discard_comments >("example.toml");
|
||||||
const auto data2 = toml::parse<toml::preserve_comments>("example.toml");
|
const auto data2 = toml::parse<toml::preserve_comments>("example.toml");
|
||||||
```
|
```
|
||||||
|
|
||||||
|
or macro definition.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#define TOML11_PRESERVE_COMMENTS_BY_DEFAULT
|
||||||
|
#include <toml11/toml.hpp>
|
||||||
|
```
|
||||||
|
|
||||||
|
This feature is controlled by template parameter in `toml::basic_value<...>`.
|
||||||
|
`toml::value` is an alias of `toml::basic_value<...>`.
|
||||||
|
|
||||||
|
If template paramter is explicitly specified, the return value of `toml::parse`
|
||||||
|
will be `toml::basic_value<toml::preserve_comments>`.
|
||||||
|
If the macro is defined, the alias `toml::value` will be
|
||||||
|
`toml::basic_value<toml::preserve_comments>`.
|
||||||
|
|
||||||
Comments related to a value can be obtained by `toml::value::comments()`.
|
Comments related to a value can be obtained by `toml::value::comments()`.
|
||||||
The return value has the same interface as `std::vector<std::string>`.
|
The return value has the same interface as `std::vector<std::string>`.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user