From 891a61a5e338393ea7bf69b230b0d831db79a459 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 18 Mar 2019 02:05:55 +0900 Subject: [PATCH 1/3] fix: do not move array element without checking --- toml/value.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toml/value.hpp b/toml/value.hpp index 739f676..a7f1f59 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -474,7 +474,7 @@ class value region_info_(std::make_shared(region_base{})) { array ary; ary.reserve(list.size()); - for(auto& elem : list) {ary.emplace_back(std::move(elem));} + for(const auto& elem : list) {ary.emplace_back(elem);} assigner(this->array_, std::move(ary)); } template::value, @@ -486,7 +486,7 @@ class value this->region_info_ = std::make_shared(region_base{}); array ary; ary.reserve(list.size()); - for(auto& elem : list) {ary.emplace_back(std::move(elem));} + for(const auto& elem : list) {ary.emplace_back(elem);} assigner(this->array_, std::move(ary)); return *this; } From 65c2c3c23815b245528255d0424c459e18053040 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 18 Mar 2019 10:53:04 +0900 Subject: [PATCH 2/3] fix: correctly deduce return value of visitor --- toml/value.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toml/value.hpp b/toml/value.hpp index a7f1f59..340396f 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -930,7 +930,7 @@ visit(Visitor&& visitor, toml::value& v) } template -detail::return_type_of_t +detail::return_type_of_t visit(Visitor&& visitor, toml::value&& v) { switch(v.type()) From f40fd12e259d3d07631abb2f12fb6e086a9f68f0 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 18 Mar 2019 11:09:12 +0900 Subject: [PATCH 3/3] refactor: add and rewrite comments --- toml/region.hpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/toml/region.hpp b/toml/region.hpp index db830c7..54d9106 100644 --- a/toml/region.hpp +++ b/toml/region.hpp @@ -15,7 +15,7 @@ namespace toml namespace detail { -// helper function to avoid std::string(0, 'c') +// helper function to avoid std::string(0, 'c') or std::string(iter, iter) template std::string make_string(Iterator first, Iterator last) { @@ -28,9 +28,7 @@ inline std::string make_string(std::size_t len, char c) return std::string(len, c); } -// region in a container, normally in a file content. -// shared_ptr points the resource that the iter points. -// combinators returns this. +// region_base is a base class of location and region that are defined below. // it will be used to generate better error messages. struct region_base { @@ -48,16 +46,19 @@ struct region_base virtual std::string line() const {return std::string("unknown line");} virtual std::string line_num() const {return std::string("?");} - virtual std::size_t before() const noexcept {return 0;} + // length of the region virtual std::size_t size() const noexcept {return 0;} + // number of characters in the line before the region + virtual std::size_t before() const noexcept {return 0;} + // number of characters in the line after the region virtual std::size_t after() const noexcept {return 0;} }; -// location in a container, normally in a file content. -// shared_ptr points the resource that the iter points. -// it can be used not only for resource handling, but also error message. -// +// location represents a position in a container, which contains a file content. // it can be considered as a region that contains only one character. +// +// it contains pointer to the file content and iterator that points the current +// location. template struct location final : public region_base { @@ -131,6 +132,10 @@ struct location final : public region_base const_iterator iter_; }; +// region represents a range in a container, which contains a file content. +// +// it contains pointer to the file content and iterator that points the first +// and last location. template struct region final : public region_base {