mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-09-17 17:58:09 +08:00
feat: add try_from to return result<T, E>
This commit is contained in:
@@ -7,7 +7,18 @@ namespace toml
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
struct from;
|
struct from;
|
||||||
// {
|
// {
|
||||||
// static T from_toml(const toml::value& v)
|
// template<typename TC>
|
||||||
|
// static T from_toml(const toml::basic_value<TC>& v)
|
||||||
|
// {
|
||||||
|
// // User-defined conversions ...
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct try_from;
|
||||||
|
// {
|
||||||
|
// template<typename TC>
|
||||||
|
// static result<T, error_info> try_from_toml(const toml::basic_value<TC>& v) noexcept
|
||||||
// {
|
// {
|
||||||
// // User-defined conversions ...
|
// // User-defined conversions ...
|
||||||
// }
|
// }
|
||||||
|
@@ -90,6 +90,13 @@ struct has_specialized_from_impl
|
|||||||
template<typename T, std::size_t S = sizeof(::toml::from<T>)>
|
template<typename T, std::size_t S = sizeof(::toml::from<T>)>
|
||||||
static std::true_type check(::toml::from<T>*);
|
static std::true_type check(::toml::from<T>*);
|
||||||
};
|
};
|
||||||
|
struct has_specialized_try_from_impl
|
||||||
|
{
|
||||||
|
template<typename T>
|
||||||
|
static std::false_type check(...);
|
||||||
|
template<typename T, std::size_t S = sizeof(::toml::try_from<T>)>
|
||||||
|
static std::true_type check(::toml::try_from<T>*);
|
||||||
|
};
|
||||||
struct has_specialized_into_impl
|
struct has_specialized_into_impl
|
||||||
{
|
{
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -130,6 +137,8 @@ template<typename T>
|
|||||||
struct has_specialized_from: decltype(has_specialized_from_impl::check<T>(nullptr)){};
|
struct has_specialized_from: decltype(has_specialized_from_impl::check<T>(nullptr)){};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct has_specialized_into: decltype(has_specialized_into_impl::check<T>(nullptr)){};
|
struct has_specialized_into: decltype(has_specialized_into_impl::check<T>(nullptr)){};
|
||||||
|
template<typename T>
|
||||||
|
struct has_specialized_try_from: decltype(has_specialized_try_from_impl::check<T>(nullptr)){};
|
||||||
|
|
||||||
#ifdef __INTEL_COMPILER
|
#ifdef __INTEL_COMPILER
|
||||||
#undef decltype
|
#undef decltype
|
||||||
|
Reference in New Issue
Block a user