diff --git a/include/toml11/value.hpp b/include/toml11/value.hpp index 6ac4319..b0d09e4 100644 --- a/include/toml11/value.hpp +++ b/include/toml11/value.hpp @@ -48,7 +48,7 @@ template error_info make_type_error(const basic_value&, const std::string&, const value_t); template -error_info make_not_found_error(const basic_value&, const std::string&, const std::string&); +error_info make_not_found_error(const basic_value&, const std::string&, const typename basic_value::key_type&); template void change_region_of_value(basic_value&, const basic_value&); @@ -76,6 +76,7 @@ class basic_value using array_type = typename config_type::template array_type; using table_type = typename config_type::template table_type; using comment_type = typename config_type::comment_type; + using char_type = typename string_type::value_type; private: @@ -643,6 +644,66 @@ class basic_value } #endif // TOML11_HAS_STRING_VIEW + +#if defined(TOML11_HAS_CHAR8_T) + template, string_type>>, + std::is_same, std::u8string> + >::value, std::nullptr_t> = nullptr> + basic_value(const T& x) + : basic_value(x, string_format_info{}, std::vector{}, region_type{}) + {} + template, string_type>>, + std::is_same, std::u8string> + >::value, std::nullptr_t> = nullptr> + basic_value(const T& x, string_format_info fmt) + : basic_value(x, std::move(fmt), std::vector{}, region_type{}) + {} + template, string_type>>, + std::is_same, std::u8string> + >::value, std::nullptr_t> = nullptr> + basic_value(const T& x, std::vector com) + : basic_value(x, string_format_info{}, std::move(com), region_type{}) + {} + template, string_type>>, + std::is_same, std::u8string> + >::value, std::nullptr_t> = nullptr> + basic_value(const T& x, string_format_info fmt, std::vector com) + : basic_value(x, std::move(fmt), std::move(com), region_type{}) + {} + template, string_type>>, + std::is_same, std::u8string> + >::value, std::nullptr_t> = nullptr> + basic_value(const T& x, string_format_info fmt, + std::vector com, region_type reg) + : type_(value_t::string), + string_(string_storage(detail::to_string_of(x), std::move(fmt))), + region_(std::move(reg)), comments_(std::move(com)) + {} + template, string_type>>, + std::is_same, std::u8string> + >::value, std::nullptr_t> = nullptr> + basic_value& operator=(const T& x) + { + string_format_info fmt; + if(this->is_string()) + { + fmt = this->as_string_fmt(); + } + this->cleanup(); + this->type_ = value_t::string; + this->region_ = region_type{}; + assigner(this->string_, string_storage(detail::to_string_of(x), std::move(fmt))); + return *this; + } + +#endif // TOML11_HAS_STRING_VIEW + // }}} // constructor (local_date) =========================================== {{{ @@ -2062,10 +2123,10 @@ error_info make_type_error(const basic_value& v, const std::string& fname, c v.location(), "the actual type is " + to_string(v.type())); } template -error_info make_not_found_error(const basic_value& v, const std::string& fname, const std::string& key) +error_info make_not_found_error(const basic_value& v, const std::string& fname, const typename basic_value::key_type& key) { const auto loc = v.location(); - const std::string title = fname + ": key \"" + key + "\" not found"; + const std::string title = fname + ": key \"" + to_string_of(key) + "\" not found"; std::vector> locs; if( ! loc.is_ok())