mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-12-16 03:08:52 +08:00
feat: add get<T> overload with toml::value&
This commit is contained in:
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>
|
detail::enable_if_t<detail::has_specialized_from<T>::value, T>
|
||||||
get(const basic_value<C, M, V>&);
|
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,
|
// T(const toml::value&) and T is not toml::basic_value,
|
||||||
// and it does not have `from<T>` nor `from_toml`.
|
// and it does not have `from<T>` nor `from_toml`.
|
||||||
template<typename T, typename C,
|
template<typename T, typename C,
|
||||||
@@ -272,6 +277,16 @@ detail::enable_if_t<detail::conjunction<
|
|||||||
>::value, T>
|
>::value, T>
|
||||||
get(const basic_value<C, M, V>&);
|
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.
|
// 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);
|
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 T, typename C,
|
||||||
template<typename ...> class M, template<typename ...> class V>
|
template<typename ...> class M, template<typename ...> class V>
|
||||||
@@ -465,6 +487,19 @@ get(const basic_value<C, M, V>& v)
|
|||||||
return T(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
|
// find
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user