mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-08 22:00:07 +00:00
add to_toml func
This commit is contained in:
parent
9234a34faa
commit
df3602f347
@ -724,13 +724,36 @@ value::cast()
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
// template<typename T, toml::value_t vT = toml::detail::check_type<T>()>
|
||||
// inline toml::value to_toml(T&& x)
|
||||
// {
|
||||
// return detail::to_toml_impl<T, vT>::invoke(std::forward<T>(x));
|
||||
// }
|
||||
template<typename T, toml::value_t vT = toml::detail::check_type<T>(),
|
||||
typename std::enable_if<(vT != toml::value_t::Unknown &&
|
||||
vT != value_t::Empty), std::nullptr_t>::type = nullptr>
|
||||
inline toml::value to_toml(T&& x)
|
||||
{
|
||||
return toml::value(std::forward<T>(x));
|
||||
}
|
||||
|
||||
template<typename T, toml::value_t vT = toml::detail::check_type<T>(),
|
||||
typename std::enable_if<(vT == toml::value_t::Unknown) &&
|
||||
(!toml::detail::is_map<T>::value) &&
|
||||
toml::detail::is_container<T>::value, std::nullptr_t>::type = nullptr>
|
||||
inline toml::value to_toml(T&& x)
|
||||
{
|
||||
toml::Array tmp; tmp.reserve(std::distance(std::begin(x), std::end(x)));
|
||||
for(auto iter = std::begin(x); iter != std::end(x); ++iter)
|
||||
tmp.emplace_back(*iter);
|
||||
return toml::value(std::move(tmp));
|
||||
}
|
||||
|
||||
template<typename T, toml::value_t vT = toml::detail::check_type<T>(),
|
||||
typename std::enable_if<(vT == toml::value_t::Unknown) &&
|
||||
toml::detail::is_map<T>::value, std::nullptr_t>::type = nullptr>
|
||||
inline toml::value to_toml(T&& x)
|
||||
{
|
||||
toml::Table tmp;
|
||||
for(auto iter = std::begin(x); iter != std::end(x); ++iter)
|
||||
tmp.emplace(iter->first, to_toml(iter->second));
|
||||
return toml::value(std::move(tmp));
|
||||
}
|
||||
|
||||
}// toml
|
||||
#endif// TOML_FOR_MODERN_CPP
|
||||
|
Loading…
Reference in New Issue
Block a user