Skip to content

Commit

Permalink
assert() on assignment issue fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Jun 5, 2017
1 parent d1e4c25 commit 7292a1d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/include/opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ namespace mp {
using storage_type = typename traits_type::storage_type;
storage_type storage_;

constexpr const T* data() const { return reinterpret_cast<const T*>(&storage_); }
constexpr T* data() { ; return reinterpret_cast<T*>(&storage_); }

public:
// constructors
constexpr opt() noexcept(noexcept(storage_type{traits_type::null_value()})) : storage_{traits_type::null_value()} {}
Expand Down Expand Up @@ -175,7 +178,7 @@ namespace mp {
std::is_constructible<T, U>, std::is_assignable<T&, U>> = true>
opt& operator=(U&& value)
{
**this = std::forward<U>(value);
*data() = std::forward<U>(value);
assert(has_value());
return *this;
}
Expand Down Expand Up @@ -214,12 +217,12 @@ namespace mp {
}

// observers
constexpr const T* operator->() const { assert(has_value()); return reinterpret_cast<const T*>(&storage_); }
constexpr T* operator->() { assert(has_value()); return reinterpret_cast<T*>(&storage_); }
constexpr const T& operator*() const & { assert(has_value()); return *reinterpret_cast<const T*>(&storage_); }
constexpr T& operator*() & { assert(has_value()); return *reinterpret_cast<T*>(&storage_); }
constexpr T&& operator*() && { assert(has_value()); return std::move(*reinterpret_cast<T*>(&storage_)); }
constexpr const T&& operator*() const && { assert(has_value()); return std::move(*reinterpret_cast<const T*>(&storage_)); }
constexpr const T* operator->() const { assert(has_value()); return data(); }
constexpr T* operator->() { assert(has_value()); return data(); }
constexpr const T& operator*() const & { assert(has_value()); return *data(); }
constexpr T& operator*() & { assert(has_value()); return *data(); }
constexpr T&& operator*() && { assert(has_value()); return std::move(*data()); }
constexpr const T&& operator*() const && { assert(has_value()); return std::move(*data()); }

constexpr bool has_value() const noexcept(noexcept(traits_type::has_value(std::declval<storage_type>())))
{
Expand Down

0 comments on commit 7292a1d

Please sign in to comment.