feat: add try_from to return result<T, E>

This commit is contained in:
ToruNiina
2024-06-28 00:09:29 +09:00
parent 2baa47ef3d
commit 8efb305e8b
2 changed files with 21 additions and 1 deletions

View File

@@ -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 ...
// } // }

View File

@@ -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