From 4efae93585055948043f83c0ea5f03c658551a4c Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Mon, 17 Jun 2024 00:56:07 +0900 Subject: [PATCH] feat: update single_include --- single_include/toml.hpp | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/single_include/toml.hpp b/single_include/toml.hpp index eee06bb9..f52580cb 100644 --- a/single_include/toml.hpp +++ b/single_include/toml.hpp @@ -4026,14 +4026,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) @@ -4146,7 +4148,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()) @@ -4162,7 +4169,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(); @@ -4261,8 +4274,12 @@ struct result #if defined(__GNUC__) && ! defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wduplicated-branches" +#endif + if(this->is_ok_) {this->succ.~success_type();} else {this->fail.~failure_type();} + +#if defined(__GNUC__) && ! defined(__clang__) #pragma GCC diagnostic pop #endif return;