From ab1ef63da6eab4acc2b7186a7e6fbeaa828b5a0f Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 21 Jun 2019 14:31:28 +0900 Subject: [PATCH] doc: add value ctor with comments to README --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index c67772e..cdd997f 100644 --- a/README.md +++ b/README.md @@ -869,9 +869,20 @@ v.comments().push_back(" add this comment."); // i = 42 ``` +Also, you can pass a `std::vector` when constructing a +`toml::basic_value`. + +```cpp +std::vector comments{"comment 1", "comment 2"}; +const toml::basic_value v1(42, std::move(comments)); +const toml::basic_value v2(42, {"comment 1", "comment 2"}); +``` + When `toml::discard_comments` is chosen, comments will not be contained in a value. `value::comments()` will always be kept empty. All the modification on comments would be ignored. +All the element access in a `discard_comments` causes the same error as accessing +an element of an empty `std::vector`. The comments will also be serialized. If comments exist, those comments will be added just before the values.