Skip to content

Commit

Permalink
Single-pass flatten_with cursor is now move-only
Browse files Browse the repository at this point in the history
  • Loading branch information
tcbrindle committed Aug 13, 2024
1 parent 1274cce commit da8cac1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions include/flux/op/flatten_with.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ struct flatten_with_adaptor : inline_sequence_base<flatten_with_adaptor<Base, Pa
std::common_reference_t<rvalue_element_t<InnerSeq>, rvalue_element_t<Pattern>>;

struct cursor_type {
constexpr explicit cursor_type(cursor_t<Base>&& outer_cur)
: outer_cur(std::move(outer_cur))
{}

cursor_type(cursor_type&&) = default;
cursor_type& operator=(cursor_type&&) = default;

cursor_t<Base> outer_cur;
std::variant<cursor_t<Pattern>, cursor_t<InnerSeq>> inner_cur{};
};
Expand Down Expand Up @@ -91,7 +98,7 @@ struct flatten_with_adaptor : inline_sequence_base<flatten_with_adaptor<Base, Pa

static constexpr auto first(self_t& self) -> cursor_type
{
cursor_type cur{.outer_cur = flux::first(self.base_)};
cursor_type cur(flux::first(self.base_));
if (!flux::is_last(self.base_, cur.outer_cur)) {
self.inner_.emplace(flux::read_at(self.base_, cur.outer_cur));
variant_emplace<1>(cur.inner_cur, flux::first(*self.inner_));
Expand Down Expand Up @@ -215,7 +222,7 @@ struct flatten_with_adaptor<Base, Pattern>
}

public:
using value_type = value_t<InnerSeq>;
using value_type = std::common_type_t<value_t<InnerSeq>, value_t<Pattern>>;

template <typename Self>
requires can_flatten<Self>
Expand Down

0 comments on commit da8cac1

Please sign in to comment.