From 4492830414467b155e5a41be261b70a2bb200366 Mon Sep 17 00:00:00 2001 From: Simon Brand Date: Fri, 8 Jun 2018 12:42:00 +0100 Subject: [PATCH] Clean up converting constructors --- tl/expected.hpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/tl/expected.hpp b/tl/expected.hpp index 34da3d6..adcf766 100644 --- a/tl/expected.hpp +++ b/tl/expected.hpp @@ -1486,11 +1486,9 @@ public: explicit TL_EXPECTED_11_CONSTEXPR expected(const expected &rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { - ::new (valptr()) T(*rhs); - this->m_has_val = true; + this->construct(*rhs); } else { - ::new (errptr()) unexpected_type(unexpected(rhs.error())); - this->m_has_val = false; + this->construct_error(rhs.error()); } } @@ -1504,12 +1502,10 @@ public: TL_EXPECTED_11_CONSTEXPR expected(const expected &rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { - ::new (valptr()) T(*rhs); - this->m_has_val = true; + this->construct(*rhs); } else { - ::new (errptr()) unexpected_type(unexpected(rhs.error())); - this->m_has_val = false; - } + this->construct_error(rhs.error()); + } } template < @@ -1520,12 +1516,10 @@ public: explicit TL_EXPECTED_11_CONSTEXPR expected(expected &&rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { - ::new (valptr()) T(std::move(*rhs)); - this->m_has_val = true; + this->construct(std::move(*rhs)); } else { - ::new (errptr()) unexpected_type(unexpected(std::move(rhs.error()))); - this->m_has_val = false; - } + this->construct_error(std::move(rhs.error())); + } } /// \exclude @@ -1537,12 +1531,10 @@ public: TL_EXPECTED_11_CONSTEXPR expected(expected &&rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { - ::new (valptr()) T(std::move(*rhs)); - this->m_has_val = true; + this->construct(std::move(*rhs)); } else { - ::new (errptr()) unexpected_type(unexpected(std::move(rhs.error()))); - this->m_has_val = false; - } + this->construct_error(std::move(rhs.error())); + } } template <