From c87c0e39756062fbc761698e96978b0936005b0e Mon Sep 17 00:00:00 2001 From: Crzyrndm Date: Sat, 7 Jul 2018 21:14:44 +1200 Subject: [PATCH] address CI build failure Issue #300 --- include/xlnt/utils/optional.hpp | 96 +++++++++++++++++---------------- 1 file changed, 49 insertions(+), 47 deletions(-) diff --git a/include/xlnt/utils/optional.hpp b/include/xlnt/utils/optional.hpp index 75fd4ac5..b91433bc 100644 --- a/include/xlnt/utils/optional.hpp +++ b/include/xlnt/utils/optional.hpp @@ -92,6 +92,54 @@ public: } } + /// + /// Copies the value into the stored value + /// + void set(const T &value) noexcept(std::is_nothrow_copy_constructible{} && std::is_nothrow_assignable{}) + { + if (has_value_) + { + value_ref() = value; + } + else + { + new (&storage_) T(value); + has_value_ = true; + } + } + + /// + /// Moves the value into the stored value + /// + void set(T &&value) noexcept(std::is_nothrow_move_constructible{} && std::is_nothrow_move_assignable{}) + { + // note seperate overload for two reasons (as opposed to perfect forwarding) + // 1. have to deal with implicit conversions internally with perfect forwarding + // 2. have to deal with the noexcept specfiers for all the different variations + // overload is just far and away the simpler solution + if (has_value_) + { + value_ref() = std::move(value); + } + else + { + new (&storage_) T(std::move(value)); + has_value_ = true; + } + } + + /// + /// After this is called, is_set() will return false until a new value is provided. + /// + void clear() noexcept(std::is_nothrow_destructible{}) + { + if (has_value_) + { + reinterpret_cast(&storage_)->~T(); + } + has_value_ = false; + } + /// /// Copy assignment of this optional from other /// noexcept if set and clear are noexcept for T& @@ -144,42 +192,6 @@ public: return has_value_; } - /// - /// Copies the value into the stored value - /// - void set(const T &value) noexcept(std::is_nothrow_copy_constructible{} && std::is_nothrow_assignable{}) - { - if (has_value_) - { - value_ref() = value; - } - else - { - new (&storage_) T(value); - has_value_ = true; - } - } - - /// - /// Moves the value into the stored value - /// - void set(T &&value) noexcept(std::is_nothrow_move_constructible{} && std::is_nothrow_move_assignable{}) - { - // note seperate overload for two reasons (as opposed to perfect forwarding) - // 1. have to deal with implicit conversions internally with perfect forwarding - // 2. have to deal with the noexcept specfiers for all the different variations - // overload is just far and away the simpler solution - if (has_value_) - { - value_ref() = std::move(value); - } - else - { - new (&storage_) T(std::move(value)); - has_value_ = true; - } - } - /// /// Assignment operator overload. Equivalent to setting the value using optional::set. /// @@ -198,17 +210,7 @@ public: return *this; } - /// - /// After this is called, is_set() will return false until a new value is provided. - /// - void clear() noexcept(std::is_nothrow_destructible{}) - { - if (has_value_) - { - reinterpret_cast(&storage_)->~T(); - } - has_value_ = false; - } + /// /// Gets the value. If no value has been initialized in this object,