From 835d38a22b32875782e257c7b063e3077e430e05 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 17 Jun 2024 00:21:11 +0900 Subject: [PATCH] feat: add SFINAE to result template ctor --- include/toml11/result.hpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/include/toml11/result.hpp b/include/toml11/result.hpp index 1da4aee..c931aee 100644 --- a/include/toml11/result.hpp +++ b/include/toml11/result.hpp @@ -186,14 +186,16 @@ struct result result(success_type s): is_ok_(true), succ(std::move(s)) {} result(failure_type f): is_ok_(false), fail(std::move(f)) {} - template, value_type>::value, - std::nullptr_t> = nullptr> + template, value_type>>, + std::is_convertible, value_type> + >::value, std::nullptr_t> = nullptr> result(success s): is_ok_(true), succ(std::move(s.value)) {} - template, error_type>::value, - std::nullptr_t> = nullptr> + template, error_type>>, + std::is_convertible, error_type> + >::value, std::nullptr_t> = nullptr> result(failure f): is_ok_(false), fail(std::move(f.value)) {} result& operator=(success_type s) @@ -306,7 +308,12 @@ struct result return *this; } - template + template, value_type>>, + cxx::negation, error_type>>, + std::is_convertible, value_type>, + std::is_convertible, error_type> + >::value, std::nullptr_t> = nullptr> result(result other): is_ok_(other.is_ok()) { if(other.is_ok()) @@ -322,7 +329,13 @@ struct result (void)tmp; } } - template + + template, value_type>>, + cxx::negation, error_type>>, + std::is_convertible, value_type>, + std::is_convertible, error_type> + >::value, std::nullptr_t> = nullptr> result& operator=(result other) { this->cleanup();