Skip to content

Commit

Permalink
Update single header
Browse files Browse the repository at this point in the history
  • Loading branch information
tcbrindle authored and github-actions[bot] committed Dec 13, 2023
1 parent 9adb7f4 commit a45d844
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions single_include/flux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,11 +1090,16 @@ class optional<T> {
constexpr optional& operator=(optional const& other)
noexcept(std::is_nothrow_copy_assignable_v<T> &&
std::is_nothrow_copy_constructible_v<T>)
requires std::copyable<T>
requires std::copy_constructible<T>
{
if (engaged_) {
if (other.engaged_) {
item_ = other.item_;
if constexpr (std::is_copy_assignable_v<T>) {
item_ = other.item_;
} else {
reset();
construct(other.item_);
}
} else {
reset();
}
Expand All @@ -1107,7 +1112,8 @@ class optional<T> {
}

optional& operator=(optional const&)
requires std::copyable<T> && std::is_trivially_copy_assignable_v<T>
requires std::copy_constructible<T> &&
std::is_trivially_copy_assignable_v<T>
= default;

/*
Expand All @@ -1133,11 +1139,16 @@ class optional<T> {
constexpr optional& operator=(optional&& other)
noexcept(std::is_nothrow_move_constructible_v<T> &&
std::is_nothrow_move_assignable_v<T>)
requires std::movable<T>
requires std::move_constructible<T>
{
if (engaged_) {
if (other.engaged_) {
item_ = std::move(other.item_);
if constexpr (std::is_move_assignable_v<T>) {
item_ = std::move(other).item_;
} else {
reset();
construct(std::move(other).item_);
}
} else {
reset();
}
Expand All @@ -1150,7 +1161,7 @@ class optional<T> {
}

constexpr optional& operator=(optional&&)
requires std::movable<T> &&
requires std::move_constructible<T> &&
std::is_trivially_move_assignable_v<T>
= default;

Expand Down Expand Up @@ -1429,6 +1440,10 @@ class optional<T&> {
*/
constexpr auto reset() -> void { ptr_ = nullptr; }

template <typename U = T>
requires requires(U& u) { test_fn(u); }
constexpr auto emplace(U& item) -> void { ptr_ = std::addressof(item); }

/*
* Monadic operations
*/
Expand Down Expand Up @@ -8408,8 +8423,8 @@ struct flatten_adaptor : inline_sequence_base<flatten_adaptor<Base>> {
static constexpr auto satisfy(auto& self, cursor_type& cur) -> void
{
while (!flux::is_last(self.base_, cur.outer_cur)) {
self.inner_ = optional<InnerSeq>(flux::read_at(self.base_, cur.outer_cur));
cur.inner_cur = optional(flux::first(*self.inner_));
self.inner_.emplace(flux::read_at(self.base_, cur.outer_cur));
cur.inner_cur.emplace(flux::first(*self.inner_));
if (!flux::is_last(*self.inner_, *cur.inner_cur)) {
return;
}
Expand Down

0 comments on commit a45d844

Please sign in to comment.