mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-21 20:10:05 +00:00
feat: add get<T> overload with toml::value&
This commit is contained in:
parent
40eb1d2213
commit
e36eabf216
35
toml/get.hpp
35
toml/get.hpp
@ -260,6 +260,11 @@ template<typename T, typename C,
|
||||
detail::enable_if_t<detail::has_specialized_from<T>::value, T>
|
||||
get(const basic_value<C, M, V>&);
|
||||
|
||||
template<typename T, typename C,
|
||||
template<typename ...> class M, template<typename ...> class V>
|
||||
detail::enable_if_t<detail::has_specialized_from<T>::value, T>
|
||||
get(basic_value<C, M, V>&);
|
||||
|
||||
// T(const toml::value&) and T is not toml::basic_value,
|
||||
// and it does not have `from<T>` nor `from_toml`.
|
||||
template<typename T, typename C,
|
||||
@ -272,6 +277,16 @@ detail::enable_if_t<detail::conjunction<
|
||||
>::value, T>
|
||||
get(const basic_value<C, M, V>&);
|
||||
|
||||
template<typename T, typename C,
|
||||
template<typename ...> class M, template<typename ...> class V>
|
||||
detail::enable_if_t<detail::conjunction<
|
||||
detail::negation<detail::is_basic_value<T>>,
|
||||
std::is_constructible<T, basic_value<C, M, V>&>,
|
||||
detail::negation<detail::has_from_toml_method<T, C, M, V>>,
|
||||
detail::negation<detail::has_specialized_from<T>>
|
||||
>::value, T>
|
||||
get(basic_value<C, M, V>&);
|
||||
|
||||
// ============================================================================
|
||||
// array-like types; most likely STL container, like std::vector, etc.
|
||||
|
||||
@ -451,6 +466,13 @@ get(const basic_value<C, M, V>& v)
|
||||
{
|
||||
return ::toml::from<T>::from_toml(v);
|
||||
}
|
||||
template<typename T, typename C,
|
||||
template<typename ...> class M, template<typename ...> class V>
|
||||
detail::enable_if_t<detail::has_specialized_from<T>::value, T>
|
||||
get(basic_value<C, M, V>& v)
|
||||
{
|
||||
return ::toml::from<T>::from_toml(v);
|
||||
}
|
||||
|
||||
template<typename T, typename C,
|
||||
template<typename ...> class M, template<typename ...> class V>
|
||||
@ -465,6 +487,19 @@ get(const basic_value<C, M, V>& v)
|
||||
return T(v);
|
||||
}
|
||||
|
||||
template<typename T, typename C,
|
||||
template<typename ...> class M, template<typename ...> class V>
|
||||
detail::enable_if_t<detail::conjunction<
|
||||
detail::negation<detail::is_basic_value<T>>, // T is not a toml::value
|
||||
std::is_constructible<T, basic_value<C, M, V>&>, // T is constructible from toml::value
|
||||
detail::negation<detail::has_from_toml_method<T, C, M, V>>, // and T does not have T.from_toml(v);
|
||||
detail::negation<detail::has_specialized_from<T>> // and T does not have toml::from<T>{};
|
||||
>::value, T>
|
||||
get(basic_value<C, M, V>& v)
|
||||
{
|
||||
return T(v);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// find
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user