From 5e5a7572087df6c37ecadf3e86482fc35500c388 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Thu, 20 Jun 2019 14:35:38 +0900 Subject: [PATCH] fix: conversion between different basic_value s --- toml/value.hpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/toml/value.hpp b/toml/value.hpp index bc95ceb..52d7b43 100644 --- a/toml/value.hpp +++ b/toml/value.hpp @@ -406,7 +406,7 @@ class basic_value basic_value& operator=(const basic_value& v) { this->region_info_ = v.region_info_; - this->comments_ = v.comments(); + this->comments_ = comment_type(v.comments()); this->type_ = v.type(); switch(v.type()) { @@ -806,26 +806,32 @@ class basic_value detail::negation>, detail::is_container >::value, std::nullptr_t>::type = nullptr> - basic_value(T&& list) + basic_value(const T& list) : type_(value_t::array), region_info_(std::make_shared(region_base{})) { - array_type ary; ary.reserve(list.size()); - for(const auto& elem : list) {ary.emplace_back(elem);} + static_assert(std::is_convertible::value, + "elements of a container should be convertible to toml::value"); + + array_type ary(list.size()); + std::copy(list.begin(), list.end(), ary.begin()); assigner(this->array_, std::move(ary)); } template>, detail::is_container >::value, std::nullptr_t>::type = nullptr> - basic_value& operator=(T&& list) + basic_value& operator=(const T& list) { + static_assert(std::is_convertible::value, + "elements of a container should be convertible to toml::value"); + this->cleanup(); this->type_ = value_t::array; this->region_info_ = std::make_shared(region_base{}); - array_type ary; ary.reserve(list.size()); - for(const auto& elem : list) {ary.emplace_back(elem);} + array_type ary(list.size()); + std::copy(list.begin(), list.end(), ary.begin()); assigner(this->array_, std::move(ary)); return *this; } @@ -1375,6 +1381,7 @@ operator==(const basic_value& lhs, const basic_value& rhs) { if(lhs.type() != rhs.type()) {return false;} if(lhs.comments() != rhs.comments()) {return false;} + switch(lhs.type()) { case value_t::boolean :