From 8efb305e8ba3b585d44eba31cda35551a9f5a52e Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Fri, 28 Jun 2024 00:09:29 +0900 Subject: [PATCH] feat: add try_from to return result --- include/toml11/from.hpp | 13 ++++++++++++- include/toml11/traits.hpp | 9 +++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/toml11/from.hpp b/include/toml11/from.hpp index d2e0e13..280cc40 100644 --- a/include/toml11/from.hpp +++ b/include/toml11/from.hpp @@ -7,7 +7,18 @@ namespace toml template struct from; // { -// static T from_toml(const toml::value& v) +// template +// static T from_toml(const toml::basic_value& v) +// { +// // User-defined conversions ... +// } +// }; + +template +struct try_from; +// { +// template +// static result try_from_toml(const toml::basic_value& v) noexcept // { // // User-defined conversions ... // } diff --git a/include/toml11/traits.hpp b/include/toml11/traits.hpp index 0a0fa79..946f760 100644 --- a/include/toml11/traits.hpp +++ b/include/toml11/traits.hpp @@ -90,6 +90,13 @@ struct has_specialized_from_impl template)> static std::true_type check(::toml::from*); }; +struct has_specialized_try_from_impl +{ + template + static std::false_type check(...); + template)> + static std::true_type check(::toml::try_from*); +}; struct has_specialized_into_impl { template @@ -130,6 +137,8 @@ template struct has_specialized_from: decltype(has_specialized_from_impl::check(nullptr)){}; template struct has_specialized_into: decltype(has_specialized_into_impl::check(nullptr)){}; +template +struct has_specialized_try_from: decltype(has_specialized_try_from_impl::check(nullptr)){}; #ifdef __INTEL_COMPILER #undef decltype