enable toml::from_toml to get static array (like std::array)

This commit is contained in:
ToruNiina
2017-05-07 10:40:47 +09:00
parent 3203d39dad
commit 726a70cd8f
2 changed files with 30 additions and 31 deletions

View File

@@ -28,11 +28,21 @@ void from_toml(T& x, const toml::value& v)
throw type_error("from_toml: value type: " + stringize(v.type()) +
std::string(" is not argument type: Array"));
const auto& ar = v.cast<value_t::Array>();
try
{
toml::resize(x, ar.size());
}
catch(std::invalid_argument& iv)
{
throw toml::type_error("toml::from_toml: static array size is not enough");
}
auto iter = x.begin();
for(const auto& val : ar)
{
typename T::value_type v;
from_toml(v, val);
x.push_back(std::move(v));
*iter = std::move(v);
++iter;
}
return;
}