From f2c8d0e2792e961381ae641718e330153b9d5b58 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 19 Jan 2020 17:51:24 +0900 Subject: [PATCH 1/3] refactor: add missing explicit to toml::exception --- toml/exception.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toml/exception.hpp b/toml/exception.hpp index 1b0005e..42ae3b1 100644 --- a/toml/exception.hpp +++ b/toml/exception.hpp @@ -12,7 +12,7 @@ namespace toml struct exception : public std::exception { public: - exception(const source_location& loc): loc_(loc) {} + explicit exception(const source_location& loc): loc_(loc) {} virtual ~exception() noexcept override = default; virtual const char* what() const noexcept override {return "";} virtual source_location const& location() const noexcept {return loc_;} From 0934d90f90f05b81147b0efc81412d2acdf0798f Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 19 Jan 2020 18:30:27 +0900 Subject: [PATCH 2/3] refactor: move ctors that are only used internally --- toml/value.hpp | 173 +++++++++++++++++++++++++------------------------ 1 file changed, 87 insertions(+), 86 deletions(-) diff --git a/toml/value.hpp b/toml/value.hpp index 9e44cba..5defd95 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -529,14 +529,6 @@ class basic_value assigner(this->boolean_, b); return *this; } - template - basic_value(boolean b, detail::region reg) - : type_(value_t::boolean), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->boolean_, b); - } basic_value(boolean b, std::vector comments) : type_(value_t::boolean), region_info_(std::make_shared(region_base{})), @@ -557,19 +549,6 @@ class basic_value assigner(this->integer_, static_cast(i)); } - template, - detail::negation> - >::value, std::nullptr_t>::type = nullptr> - basic_value(T i, detail::region reg) - : type_(value_t::integer), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->integer_, static_cast(i)); - } - template, detail::negation>>::value, std::nullptr_t>::type = nullptr> @@ -604,15 +583,6 @@ class basic_value assigner(this->floating_, static_cast(f)); } - template::value, std::nullptr_t>::type = nullptr> - basic_value(T f, detail::region reg) - : type_(value_t::floating), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->floating_, static_cast(f)); - } template::value, std::nullptr_t>::type = nullptr> @@ -643,14 +613,6 @@ class basic_value { assigner(this->string_, std::move(s)); } - template - basic_value(toml::string s, detail::region reg) - : type_(value_t::string), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->string_, std::move(s)); - } basic_value& operator=(toml::string s) { this->cleanup(); @@ -782,14 +744,6 @@ class basic_value { assigner(this->local_date_, ld); } - template - basic_value(const local_date& ld, detail::region reg) - : type_(value_t::local_date), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->local_date_, ld); - } basic_value& operator=(const local_date& ld) { this->cleanup(); @@ -814,14 +768,6 @@ class basic_value { assigner(this->local_time_, lt); } - template - basic_value(const local_time& lt, detail::region reg) - : type_(value_t::local_time), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->local_time_, lt); - } basic_value(const local_time& lt, std::vector comments) : type_(value_t::local_time), region_info_(std::make_shared(region_base{})), @@ -872,14 +818,6 @@ class basic_value { assigner(this->local_datetime_, ldt); } - template - basic_value(const local_datetime& ldt, detail::region reg) - : type_(value_t::local_datetime), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->local_datetime_, ldt); - } basic_value(const local_datetime& ldt, std::vector comments) : type_(value_t::local_datetime), region_info_(std::make_shared(region_base{})), @@ -904,14 +842,6 @@ class basic_value { assigner(this->offset_datetime_, odt); } - template - basic_value(const offset_datetime& odt, detail::region reg) - : type_(value_t::offset_datetime), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->offset_datetime_, odt); - } basic_value(const offset_datetime& odt, std::vector comments) : type_(value_t::offset_datetime), region_info_(std::make_shared(region_base{})), @@ -958,14 +888,6 @@ class basic_value { assigner(this->array_, ary); } - template - basic_value(const array_type& ary, detail::region reg) - : type_(value_t::array), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->array_, ary); - } basic_value(const array_type& ary, std::vector comments) : type_(value_t::array), region_info_(std::make_shared(region_base{})), @@ -1079,14 +1001,6 @@ class basic_value { assigner(this->table_, tab); } - template - basic_value(const table_type& tab, detail::region reg) - : type_(value_t::table), - region_info_(std::make_shared>(std::move(reg))), - comments_(region_info_->comments()) - { - assigner(this->table_, tab); - } basic_value(const table_type& tab, std::vector comments) : type_(value_t::table), region_info_(std::make_shared(region_base{})), @@ -1216,6 +1130,93 @@ class basic_value } // for internal use ------------------------------------------------------ + // + // Those constructors take detail::region that contains parse result. + + template + basic_value(boolean b, detail::region reg) + : type_(value_t::boolean), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->boolean_, b); + } + template, detail::negation> + >::value, std::nullptr_t>::type = nullptr> + basic_value(T i, detail::region reg) + : type_(value_t::integer), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->integer_, static_cast(i)); + } + template::value, std::nullptr_t>::type = nullptr> + basic_value(T f, detail::region reg) + : type_(value_t::floating), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->floating_, static_cast(f)); + } + template + basic_value(toml::string s, detail::region reg) + : type_(value_t::string), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->string_, std::move(s)); + } + template + basic_value(const local_date& ld, detail::region reg) + : type_(value_t::local_date), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->local_date_, ld); + } + template + basic_value(const local_time& lt, detail::region reg) + : type_(value_t::local_time), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->local_time_, lt); + } + template + basic_value(const local_datetime& ldt, detail::region reg) + : type_(value_t::local_datetime), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->local_datetime_, ldt); + } + template + basic_value(const offset_datetime& odt, detail::region reg) + : type_(value_t::offset_datetime), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->offset_datetime_, odt); + } + template + basic_value(const array_type& ary, detail::region reg) + : type_(value_t::array), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->array_, ary); + } + template + basic_value(const table_type& tab, detail::region reg) + : type_(value_t::table), + region_info_(std::make_shared>(std::move(reg))), + comments_(region_info_->comments()) + { + assigner(this->table_, tab); + } template::value, From f7bf341452f01d695585fae817bfa81c42648349 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 19 Jan 2020 21:06:10 +0900 Subject: [PATCH 3/3] fix: add missing noexcept specifier --- toml/value.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toml/value.hpp b/toml/value.hpp index 5defd95..63df1fc 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -1248,7 +1248,7 @@ class basic_value bool is_array() const noexcept {return this->is(value_t::array );} bool is_table() const noexcept {return this->is(value_t::table );} - value_t type() const {return type_;} + value_t type() const noexcept {return type_;} template typename detail::enum_to_type::type& cast() &