mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 09:08:08 +08:00
simplify SFINAE in to_toml
This commit is contained in:
@@ -5,47 +5,76 @@
|
||||
namespace toml
|
||||
{
|
||||
|
||||
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)
|
||||
template<typename T, typename std::enable_if<
|
||||
detail::is_exact_toml_type<T>::value, std::nullptr_t>::type = nullptr>
|
||||
inline value to_toml(const T& x)
|
||||
{
|
||||
return toml::value(std::forward<T>(x));
|
||||
return value(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>
|
||||
toml::value to_toml(T&& x)
|
||||
template<typename T, typename std::enable_if<detail::conjunction<
|
||||
detail::negation<detail::is_exact_toml_type<T>>, std::is_integral<T>
|
||||
>::value, std::nullptr_t>::type = nullptr>
|
||||
inline value to_toml(const T& x)
|
||||
{
|
||||
toml::Array tmp; tmp.reserve(std::distance(std::begin(x), std::end(x)));
|
||||
return value(::toml::Integer(x));
|
||||
}
|
||||
|
||||
template<typename T, typename std::enable_if<detail::conjunction<
|
||||
detail::negation<detail::is_exact_toml_type<T>>, std::is_floating_point<T>
|
||||
>::value, std::nullptr_t>::type = nullptr>
|
||||
inline value to_toml(const T& x)
|
||||
{
|
||||
return value(::toml::Float(x));
|
||||
}
|
||||
|
||||
inline value to_toml(const char* str)
|
||||
{
|
||||
return value(::toml::String(str));
|
||||
}
|
||||
|
||||
template<typename T, typename std::enable_if<detail::conjunction<
|
||||
detail::negation<detail::is_exact_toml_type<T>>, detail::is_container<T>
|
||||
>::value, std::nullptr_t>::type = nullptr>
|
||||
value to_toml(const T& x)
|
||||
{
|
||||
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));
|
||||
}
|
||||
return 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>
|
||||
toml::value to_toml(T&& x)
|
||||
template<typename T, typename std::enable_if<detail::conjunction<
|
||||
detail::negation<detail::is_exact_toml_type<T>>, detail::is_map<T>
|
||||
>::value, std::nullptr_t>::type = nullptr>
|
||||
value to_toml(const T& x)
|
||||
{
|
||||
toml::Table tmp;
|
||||
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));
|
||||
}
|
||||
return value(std::move(tmp));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline toml::value to_toml(std::initializer_list<T> init)
|
||||
inline value to_toml(std::initializer_list<T> init)
|
||||
{
|
||||
return toml::value(std::move(init));
|
||||
return value(std::move(init));
|
||||
}
|
||||
|
||||
inline toml::value
|
||||
to_toml(std::initializer_list<std::pair<std::string, toml::value>> init)
|
||||
inline value to_toml(std::initializer_list<std::pair<std::string, value>> init)
|
||||
{
|
||||
return toml::value(std::move(init));
|
||||
return value(std::move(init));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline value to_toml(const value& x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
} // toml
|
||||
|
Reference in New Issue
Block a user