From d88521d63c2f29b0e6e91ddd60ec4e99728a307a Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 4 Mar 2019 15:01:28 +0900 Subject: [PATCH] feat: enable to change region of value To allow the following toml file, we need to replace the region after the more precise region is found. ```toml [a.b.c] d = 42 [a] e = 2.71 ``` If the precise region (here, [a]) is found, the region of `a` should be `[a]`, not `[a.b.c]`. After `[a]` is defined, toml does not allow to write `[a]` twice. To check it, we need to replace the region of values to the precise one. --- toml/value.hpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/toml/value.hpp b/toml/value.hpp index d6f5f0e..03812c7 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -21,6 +21,8 @@ namespace detail { // to show error messages. not recommended for users. region_base const& get_region(const value&); +template +void change_region(value&, Region&&); }// detail template @@ -560,6 +562,9 @@ class value // for error messages friend region_base const& detail::get_region(const value&); + template + friend void detail::change_region(value&, Region&&); + template struct switch_cast; @@ -594,6 +599,20 @@ inline region_base const& get_region(const value& v) { return *(v.region_info_); } + +template +void change_region(value& v, Region&& reg) +{ + using region_type = typename std::remove_reference< + typename std::remove_cv::type + >::type; + + std::shared_ptr new_reg = + std::make_shared(std::forward(reg)); + v.region_info_ = new_reg; + return; +} + }// detail template<> struct value::switch_cast