refactor: show func name in bad_cast from helpers

This commit is contained in:
ToruNiina
2020-03-21 17:06:34 +09:00
parent 653c87592c
commit c2151cab0b

View File

@@ -1728,11 +1728,8 @@ class basic_value
{ {
if(this->type_ != value_t::array) if(this->type_ != value_t::array)
{ {
throw type_error(detail::format_underline( detail::throw_bad_cast<value_t::array>(
"toml::value::push_back(value): bad_cast to array type", { "toml::value::push_back(value): ", this->type_, *this);
{this->region_info_.get(),
concat_to_string("the actual type is ", this->type_)}
}), this->location());
} }
this->as_array(std::nothrow).push_back(x); this->as_array(std::nothrow).push_back(x);
return; return;
@@ -1741,11 +1738,8 @@ class basic_value
{ {
if(this->type_ != value_t::array) if(this->type_ != value_t::array)
{ {
throw type_error(detail::format_underline( detail::throw_bad_cast<value_t::array>(
"toml::value::push_back(value): bad_cast to array type", { "toml::value::push_back(value): ", this->type_, *this);
{this->region_info_.get(),
concat_to_string("the actual type is ", this->type_)}
}), this->location());
} }
this->as_array(std::nothrow).push_back(std::move(x)); this->as_array(std::nothrow).push_back(std::move(x));
return; return;
@@ -1756,11 +1750,8 @@ class basic_value
{ {
if(this->type_ != value_t::array) if(this->type_ != value_t::array)
{ {
throw type_error(detail::format_underline( detail::throw_bad_cast<value_t::array>(
"toml::value::emplace_back(value): bad_cast to array type", { "toml::value::emplace_back(...): ", this->type_, *this);
{this->region_info_.get(),
concat_to_string("the actual type is ", this->type_)}
}), this->location());
} }
this->as_array(std::nothrow).emplace_back(std::forward<Ts>(args) ...); this->as_array(std::nothrow).emplace_back(std::forward<Ts>(args) ...);
return this->as_array(std::nothrow).back(); return this->as_array(std::nothrow).back();
@@ -1795,28 +1786,22 @@ class basic_value
std::size_t count(const key_type& k) const std::size_t count(const key_type& k) const
{ {
if(this->type_ != value_t::table) if(!this->is_table())
{ {
throw type_error(detail::format_underline( detail::throw_bad_cast<value_t::table>(
"toml::value::count(key): bad_cast to table type", { "toml::value::count(key): ", this->type_, *this);
{this->region_info_.get(),
concat_to_string("the actual type is ", this->type_)}
}), this->location());
} }
return this->as_table().count(k); return this->as_table(std::nothrow).count(k);
} }
bool contains(const key_type& k) const bool contains(const key_type& k) const
{ {
if(this->type_ != value_t::table) if(!this->is_table())
{ {
throw type_error(detail::format_underline( detail::throw_bad_cast<value_t::table>(
"toml::value::contains(key): bad_cast to table type", { "toml::value::contains(key): ", this->type_, *this);
{this->region_info_.get(),
concat_to_string("the actual type is ", this->type_)}
}), this->location());
} }
return (this->as_table().count(k) != 0); return (this->as_table(std::nothrow).count(k) != 0);
} }
source_location location() const source_location location() const