Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4b299d8
Add iterable concept
tcbrindle Sep 11, 2024
7bd0dd0
Make all input ranges iterable
tcbrindle Sep 11, 2024
b8f12f5
Make for_each operate on iterables
tcbrindle Sep 11, 2024
3d9c2c0
Make some algorithms operate on iterables...
tcbrindle Sep 12, 2024
975797d
Modify flux::to to use iterables
tcbrindle Sep 12, 2024
5970c5c
read_only_sequence -> read_only_iterable
tcbrindle Oct 25, 2024
22f3870
Add new callable concepts
tcbrindle Oct 28, 2024
66733ab
Add predicate_for<Iterable> concept
tcbrindle Oct 28, 2024
09bfa83
Use new iterate() in TCO example
tcbrindle Nov 7, 2024
3c366f2
Add sink_iterable concept
tcbrindle Nov 7, 2024
1419a30
Allow flux::from() to accept iterables
tcbrindle Nov 7, 2024
c688d31
Allow filter adaptor to operate on iterables
tcbrindle Nov 7, 2024
c0fb519
sized_sequence => sized_iterable
tcbrindle Nov 7, 2024
a21b95f
Make non-contiguous ranges sized_iterables
tcbrindle Nov 7, 2024
847f668
Make flux::map() work on iterables
tcbrindle Nov 7, 2024
3067fbe
Make passthrough_traits_base support iterables
tcbrindle Nov 7, 2024
d7b227e
Make drop() work on iterables
tcbrindle Nov 7, 2024
ab78282
Make take() work on iterables
tcbrindle Nov 7, 2024
36442ad
Make flatten() work on iterables
tcbrindle Nov 12, 2024
b0bbfb4
Make chain() work on iterables
tcbrindle Nov 14, 2024
80dd9e1
Make drop_while() work with iterables
tcbrindle Nov 25, 2024
667c9f6
Make filter_map() work with iterables
tcbrindle Nov 25, 2024
4deb5bd
Make flatten_with() work with iterables
tcbrindle Nov 25, 2024
2bda737
Add missing <ranges> includes in tests
tcbrindle Nov 25, 2024
6628427
Make read_only() work with iterables
tcbrindle Nov 25, 2024
6a2b2ed
Make scan() and prescan() work with iterables
tcbrindle Nov 26, 2024
53da08b
Make scan_first() work with iterables
tcbrindle Nov 26, 2024
5efec93
Make stride() work with iterables
tcbrindle Nov 26, 2024
d1a1bf4
Make take_while() work with iterables
tcbrindle Nov 26, 2024
8616f55
Add iterate() impl to cartesian_base
tcbrindle Nov 26, 2024
b0531a7
Update .clang-format
tcbrindle Nov 26, 2024
872fd8d
Fix scan test with Clang 18
tcbrindle Nov 26, 2024
fb4bce7
Work around GCC 12 ICE
tcbrindle Nov 26, 2024
34411a2
Work around bogus MSVC errors
tcbrindle Nov 27, 2024
9883fa6
Re-enable constexpr starts_with() tests
tcbrindle Nov 27, 2024
be4186c
Rename sequence_traits -> iter_traits
tcbrindle Nov 27, 2024
f45c4f7
Rename flux_sequence_traits -> flux_iter_traits
tcbrindle Nov 27, 2024
1822f09
Rename inline_sequence_base -> inline_iter_base
tcbrindle Nov 27, 2024
2496980
Update .gitignore
tcbrindle Dec 9, 2024
588ef04
Flatten: avoid hard error with non-sequence inner
tcbrindle Dec 9, 2024
a3f7a4e
Correctly constrain inline_iter_base member fns
tcbrindle Dec 14, 2024
d74b787
Merge branch 'main' into pr/iterable
tcbrindle Dec 17, 2024
8fe8c9d
Remove erroneous #include
tcbrindle Dec 18, 2024
788dd5e
Fix take::iterate() for RA + Bounded
tcbrindle Dec 18, 2024
b5587e2
Use read_at_unchecked() in default iterate() impl
tcbrindle Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ InsertBraces: true
NamespaceIndentation: None
PackConstructorInitializers: CurrentLine
SortIncludes: Never
SpaceBeforeCpp11BracedList: false
TabWidth: 4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CMakeLists.txt.user
cmake-build*/

# VS Code
.cache/
.vscode/

# VS
Expand Down
2 changes: 1 addition & 1 deletion example/docs/read_only.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

// We can use the read_only_sequence concept to statically require a sequence
// whose elements are immutable
bool contains_a_two(flux::read_only_sequence auto&& seq)
bool contains_a_two(flux::read_only_iterable auto&& seq)
{
for (auto&& elem : seq) {
if (elem == 2) { // What if we wrote `elem = 2` (assignment) by mistake?
Expand Down
4 changes: 1 addition & 3 deletions example/top10/08_three_consecutive_odds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,14 @@ namespace version1 {

auto const tco = [](std::initializer_list<int> nums)
{
int odd_count = 0;
auto idx = flux::for_each_while(nums, [&](int i) {
return !flux::iterate(nums, [odd_count = 0](int i) mutable {
if (i % 2 != 0) {
++odd_count;
} else {
odd_count = 0;
}
return odd_count < 3; // true => keep iterating
});
return !flux::is_last(nums, idx);
};

static_assert(tco({}) == false);
Expand Down
20 changes: 10 additions & 10 deletions include/flux/adaptor/adjacent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace flux {
namespace detail {

template <typename Base, distance_t N>
struct adjacent_sequence_traits_base : default_sequence_traits {
struct adjacent_sequence_traits_base : default_iter_traits {
protected:
struct cursor_type {
std::array<cursor_t<Base>, N> arr{};
Expand Down Expand Up @@ -107,15 +107,15 @@ struct adjacent_sequence_traits_base : default_sequence_traits {
}

static constexpr auto size(auto& self) -> distance_t
requires sized_sequence<Base>
requires sized_iterable<Base>
{
auto s = (flux::size(self.base_) - N) + 1;
return (cmp::max)(s, distance_t{0});
}
};

template <typename Base, distance_t N>
struct adjacent_adaptor : inline_sequence_base<adjacent_adaptor<Base, N>> {
struct adjacent_adaptor : inline_iter_base<adjacent_adaptor<Base, N>> {
private:
Base base_;

Expand All @@ -126,7 +126,7 @@ struct adjacent_adaptor : inline_sequence_base<adjacent_adaptor<Base, N>> {
: base_(FLUX_FWD(base))
{}

struct flux_sequence_traits : adjacent_sequence_traits_base<Base, N> {
struct flux_iter_traits : adjacent_sequence_traits_base<Base, N> {
private:

using cursor_type = adjacent_sequence_traits_base<Base, N>::cursor_type;
Expand Down Expand Up @@ -176,7 +176,7 @@ struct adjacent_adaptor : inline_sequence_base<adjacent_adaptor<Base, N>> {
};

template <typename Base, distance_t N, typename Func>
struct adjacent_map_adaptor : inline_sequence_base<adjacent_map_adaptor<Base, N, Func>> {
struct adjacent_map_adaptor : inline_iter_base<adjacent_map_adaptor<Base, N, Func>> {
private:
Base base_;
Func func_;
Expand All @@ -189,7 +189,7 @@ struct adjacent_map_adaptor : inline_sequence_base<adjacent_map_adaptor<Base, N,
func_(std::move(func))
{}

struct flux_sequence_traits : adjacent_sequence_traits_base<Base, N> {
struct flux_iter_traits : adjacent_sequence_traits_base<Base, N> {
template <typename Self>
static constexpr auto read_at(Self& self, cursor_t<Self> const& cur)
-> decltype(auto)
Expand Down Expand Up @@ -244,14 +244,14 @@ FLUX_EXPORT inline constexpr auto pairwise_map = adjacent_map<2>;

template <typename D>
template <distance_t N>
constexpr auto inline_sequence_base<D>::adjacent() &&
constexpr auto inline_iter_base<D>::adjacent() &&
requires multipass_sequence<D>
{
return flux::adjacent<N>(std::move(derived()));
}

template <typename D>
constexpr auto inline_sequence_base<D>::pairwise() &&
constexpr auto inline_iter_base<D>::pairwise() &&
requires multipass_sequence<D>
{
return flux::pairwise(std::move(derived()));
Expand All @@ -260,15 +260,15 @@ constexpr auto inline_sequence_base<D>::pairwise() &&
template <typename D>
template <distance_t N, typename Func>
requires multipass_sequence<D>
constexpr auto inline_sequence_base<D>::adjacent_map(Func func) &&
constexpr auto inline_iter_base<D>::adjacent_map(Func func) &&
{
return flux::adjacent_map<N>(std::move(derived()), std::move(func));
}

template <typename D>
template <typename Func>
requires multipass_sequence<D>
constexpr auto inline_sequence_base<D>::pairwise_map(Func func) &&
constexpr auto inline_iter_base<D>::pairwise_map(Func func) &&
{
return flux::pairwise_map(std::move(derived()), std::move(func));
}
Expand Down
8 changes: 4 additions & 4 deletions include/flux/adaptor/adjacent_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace detail {

template <multipass_sequence Base, typename Pred>
struct adjacent_filter_adaptor
: inline_sequence_base<adjacent_filter_adaptor<Base, Pred>> {
: inline_iter_base<adjacent_filter_adaptor<Base, Pred>> {
private:
FLUX_NO_UNIQUE_ADDRESS Base base_;
FLUX_NO_UNIQUE_ADDRESS Pred pred_;
Expand All @@ -25,7 +25,7 @@ struct adjacent_filter_adaptor
pred_(std::move(pred))
{}

struct flux_sequence_traits : default_sequence_traits {
struct flux_iter_traits : default_iter_traits {
private:
struct cursor_type {
cursor_t<Base> base_cur;
Expand Down Expand Up @@ -145,13 +145,13 @@ template <typename D>
template <typename Pred>
requires multipass_sequence<D> &&
std::predicate<Pred&, element_t<D>, element_t<D>>
constexpr auto inline_sequence_base<D>::adjacent_filter(Pred pred) &&
constexpr auto inline_iter_base<D>::adjacent_filter(Pred pred) &&
{
return flux::adjacent_filter(std::move(derived()), std::move(pred));
}

template <typename D>
constexpr auto inline_sequence_base<D>::dedup() &&
constexpr auto inline_iter_base<D>::dedup() &&
requires multipass_sequence<D> &&
std::equality_comparable<element_t<D>>
{
Expand Down
6 changes: 3 additions & 3 deletions include/flux/adaptor/cache_last.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace flux {
namespace detail {

template <sequence Base>
struct cache_last_adaptor : inline_sequence_base<cache_last_adaptor<Base>>
struct cache_last_adaptor : inline_iter_base<cache_last_adaptor<Base>>
{
private:
Base base_;
Expand All @@ -28,7 +28,7 @@ struct cache_last_adaptor : inline_sequence_base<cache_last_adaptor<Base>>
: base_(FLUX_FWD(base))
{}

struct flux_sequence_traits : detail::passthrough_traits_base {
struct flux_iter_traits : detail::passthrough_traits_base {

using value_type = value_t<Base>;
using self_t = cache_last_adaptor;
Expand Down Expand Up @@ -79,7 +79,7 @@ struct cache_last_fn {
FLUX_EXPORT inline constexpr auto cache_last = detail::cache_last_fn{};

template <typename Derived>
constexpr auto inline_sequence_base<Derived>::cache_last() &&
constexpr auto inline_iter_base<Derived>::cache_last() &&
requires bounded_sequence<Derived> ||
(multipass_sequence<Derived> && not infinite_sequence<Derived>)
{
Expand Down
42 changes: 34 additions & 8 deletions include/flux/adaptor/cartesian_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct cartesian_traits_types<Arity, cartesian_kind::product, read_kind::tuple,
};

template <std::size_t Arity, cartesian_kind CartesianKind, read_kind ReadKind, typename... Bases>
struct cartesian_traits_base_impl : default_sequence_traits {
struct cartesian_traits_base_impl : default_iter_traits {
private:

template<std::size_t I, typename Self>
Expand Down Expand Up @@ -204,11 +204,37 @@ struct cartesian_traits_base_impl : default_sequence_traits {
}
}

template <std::size_t I, typename Self, typename Predicate,
typename... PartialElements>
static constexpr auto iterate_impl(Self& self, Predicate& pred,
PartialElements&&... partial_elements) -> bool
{
if constexpr (I == Arity - 1) {
return flux::iterate(get_base<I>(self), [&](auto&& elem) {
if constexpr (ReadKind == read_kind::tuple) {
return std::invoke(pred, element_t<Self>(FLUX_FWD(partial_elements)..., FLUX_FWD(elem)));
} else {
return std::invoke(pred, std::invoke(self.func_, FLUX_FWD(partial_elements)..., FLUX_FWD(elem)));
}
});
} else {
return flux::iterate(get_base<I>(self), [&](auto&& elem) {
return iterate_impl<I+1>(self, pred, FLUX_FWD(partial_elements)..., FLUX_FWD(elem));
});
}
}

protected:
using types = cartesian_traits_types<Arity, CartesianKind, ReadKind, Bases...>;

public:

template <typename Self, typename Pred>
static constexpr auto iterate(Self& self, Pred&& pred) -> bool
{
return iterate_impl<0>(self, pred);
}

template <typename Self>
static constexpr auto first(Self& self)
requires (CartesianKind == cartesian_kind::product)
Expand All @@ -233,7 +259,7 @@ struct cartesian_traits_base_impl : default_sequence_traits {
template <typename Self>
static constexpr auto size(Self& self) -> distance_t
requires (CartesianKind == cartesian_kind::product
&& (sized_sequence<Bases> && ...))
&& (sized_iterable<Bases> && ...))
{
return std::apply([](auto& base0, auto&... bases) {
distance_t sz = flux::size(base0);
Expand All @@ -245,7 +271,7 @@ struct cartesian_traits_base_impl : default_sequence_traits {
template <typename Self>
static constexpr auto size(Self& self) -> distance_t
requires (CartesianKind == cartesian_kind::power
&& (sized_sequence<Bases> && ...))
&& (sized_iterable<Bases> && ...))
{
return checked_pow(flux::size(self.base_), Arity);
}
Expand All @@ -269,7 +295,7 @@ struct cartesian_traits_base_impl : default_sequence_traits {
template <typename Self>
static constexpr auto inc(Self& self, cursor_t<Self>& cur, distance_t offset) -> cursor_t<Self>&
requires ((random_access_sequence<Bases> && ...) &&
(sized_sequence<Bases> && ...))
(sized_iterable<Bases> && ...))
{
return ra_inc_impl<Arity - 1>(self, cur, offset);
}
Expand Down Expand Up @@ -305,7 +331,7 @@ struct cartesian_traits_base_impl : default_sequence_traits {
cursor_t<Self> const& from,
cursor_t<Self> const& to) -> distance_t
requires ((random_access_sequence<Bases> && ...) &&
(sized_sequence<Bases> && ...))
(sized_iterable<Bases> && ...))
{
return distance_impl<Arity - 1>(self, from, to);
}
Expand Down Expand Up @@ -342,15 +368,15 @@ struct cartesian_traits_base_impl : default_sequence_traits {
-> decltype(auto)
requires (ReadKind == read_kind::map)
{
return default_sequence_traits::move_at(self, cur);
return default_iter_traits::move_at(self, cur);
}

template <typename Self>
static constexpr auto move_at_unchecked(Self& self, cursor_t<Self> const& cur)
-> decltype(auto)
requires (ReadKind == read_kind::map)
{
return default_sequence_traits::move_at_unchecked(self, cur);
return default_iter_traits::move_at_unchecked(self, cur);
}

template <typename Self>
Expand Down Expand Up @@ -389,7 +415,7 @@ struct cartesian_traits_base_impl : default_sequence_traits {
static constexpr auto for_each_while(Self& self, Function&& func) -> cursor_t<Self>
requires (ReadKind == read_kind::map)
{
return default_sequence_traits::for_each_while(self, FLUX_FWD(func));
return default_iter_traits::for_each_while(self, FLUX_FWD(func));
}

};
Expand Down
6 changes: 3 additions & 3 deletions include/flux/adaptor/cartesian_power.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace detail {

template <std::size_t PowN, sequence Base>
struct cartesian_power_adaptor
: inline_sequence_base<cartesian_power_adaptor<PowN, Base>> {
: inline_iter_base<cartesian_power_adaptor<PowN, Base>> {
private:
FLUX_NO_UNIQUE_ADDRESS Base base_;

Expand All @@ -29,13 +29,13 @@ struct cartesian_power_adaptor
: base_(FLUX_FWD(base))
{}

using flux_sequence_traits = cartesian_traits_base<
using flux_iter_traits = cartesian_traits_base<
PowN,
cartesian_kind::power,
read_kind::tuple,
Base
>;
friend flux_sequence_traits::impl;
friend flux_iter_traits::impl;
};


Expand Down
6 changes: 3 additions & 3 deletions include/flux/adaptor/cartesian_power_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace detail {

template <sequence Base, std::size_t PowN, typename Func>
struct cartesian_power_map_adaptor
: inline_sequence_base<cartesian_power_map_adaptor<Base, PowN, Func>> {
: inline_iter_base<cartesian_power_map_adaptor<Base, PowN, Func>> {
private:
FLUX_NO_UNIQUE_ADDRESS Base base_;
FLUX_NO_UNIQUE_ADDRESS Func func_;
Expand All @@ -25,13 +25,13 @@ struct cartesian_power_map_adaptor
func_(FLUX_FWD(func))
{}

using flux_sequence_traits = cartesian_traits_base<
using flux_iter_traits = cartesian_traits_base<
PowN,
cartesian_kind::power,
read_kind::map,
Base
>;
friend flux_sequence_traits::impl;
friend flux_iter_traits::impl;
};

template <std::size_t PowN>
Expand Down
6 changes: 3 additions & 3 deletions include/flux/adaptor/cartesian_product.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace detail {

template <sequence... Bases>
struct cartesian_product_adaptor
: inline_sequence_base<cartesian_product_adaptor<Bases...>> {
: inline_iter_base<cartesian_product_adaptor<Bases...>> {
private:
FLUX_NO_UNIQUE_ADDRESS std::tuple<Bases...> bases_;

Expand All @@ -29,13 +29,13 @@ struct cartesian_product_adaptor
: bases_(FLUX_FWD(bases)...)
{}

using flux_sequence_traits = cartesian_traits_base<
using flux_iter_traits = cartesian_traits_base<
sizeof...(Bases),
cartesian_kind::product,
read_kind::tuple,
Bases...
>;
friend flux_sequence_traits::impl;
friend flux_iter_traits::impl;
};

struct cartesian_product_fn {
Expand Down
Loading
Loading