diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-11-22 19:04:58 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | 53b9ec80a3b7bb7e403a8c7330c0741484b9ba4d (patch) | |
tree | ca5e967c315e08071c432a1f7b589618ed3801e5 /asl/option.hpp | |
parent | defa7e1b9e16c6276e17a39b61d019c1a116472b (diff) |
Don't force niched values to be move assignable in reset, and fix warnings
Diffstat (limited to 'asl/option.hpp')
-rw-r--r-- | asl/option.hpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/asl/option.hpp b/asl/option.hpp index 6b528b9..f2af9ee 100644 --- a/asl/option.hpp +++ b/asl/option.hpp @@ -123,8 +123,8 @@ public: // NOLINTNEXTLINE(*-explicit-conversions)
constexpr option(nullopt_t) requires (!kHasNiche)
- : m_has_value{false}
- , m_payload{}
+ : m_payload{}
+ , m_has_value{false}
{}
// NOLINTNEXTLINE(*-explicit-conversions)
@@ -383,7 +383,18 @@ public: if constexpr (kHasNiche)
{
- m_payload = T(niche{});
+ if constexpr (move_assignable<T>)
+ {
+ m_payload = T(niche{});
+ }
+ else
+ {
+ if constexpr (!trivially_destructible<T>)
+ {
+ (&m_payload)->~T();
+ }
+ new (&m_payload) T(niche{});
+ }
}
else
{
|