Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/cartesian power and map #163

Merged
merged 49 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
db7adf0
#138 Add products<N> equivalent for cartesian_product(1, ..., N)
isaacy2012 Jan 25, 2024
d72d14a
Remove debugging type deducer
isaacy2012 Jan 25, 2024
0804328
Fix indentation for read_
isaacy2012 Jan 25, 2024
69990f6
Rename products to cartesian_power for consistency with cartesian_pro…
isaacy2012 Jan 26, 2024
40648bf
Extract common functionality across cartesian product, product_with, …
isaacy2012 Jan 26, 2024
01dafe1
Use cartesian_default_read_traits_base to expose read_at, move_at, et…
isaacy2012 Jan 26, 2024
dcda99a
Change cursor_type for cartesian_power from repeated tuple to std::array
isaacy2012 Jan 27, 2024
ee59be0
Replace cartesian_product/power_is_bounded with cartesian_is_bounded
isaacy2012 Jan 27, 2024
68c634e
Remove cartesian_power_is_bounded
isaacy2012 Jan 27, 2024
9422317
Simplify cartesian_default_read_traits_base heirarchy chain
isaacy2012 Jan 27, 2024
a29da7b
Add cartesian_power_with
isaacy2012 Jan 27, 2024
cd6b847
Remove parentheses for requires for cartesian_power and cartesian_pow…
isaacy2012 Jan 27, 2024
4b6ea82
Consolidate trait heirarchy into single cartesian_traits_base with en…
isaacy2012 Jan 28, 2024
6bb83ed
Merge branch 'tcbrindle:main' into feat/cartesian-product-and-with
isaacy2012 Jan 28, 2024
0ca1166
Remove debugging test statement
isaacy2012 Jan 28, 2024
9246316
Remove empty line
isaacy2012 Jan 28, 2024
ca2cf1c
Switch from explicitly to implicitly defined cursor_t for cartesian_base
isaacy2012 Jan 28, 2024
d2b21ea
Rename adjacent_invocable to repeated_invocable and move to concepts …
isaacy2012 Jan 28, 2024
7d7af6b
Rename cartesian_power_with to cartesian_power_map
isaacy2012 Jan 28, 2024
e095c6c
Restrict explicit value_type definition for cartesian_base to read_ki…
isaacy2012 Jan 28, 2024
62aceb5
Rename cartesian_product_with to cartesian_product_map
isaacy2012 Jan 28, 2024
ebe3899
Restrict value_type to only read_kind::tuple specialisations of carte…
isaacy2012 Jan 28, 2024
8163168
Move repeated_invocable to flux/op/requirements.hpp
isaacy2012 Jan 28, 2024
1714bfb
Add static check for flux::inc with offset 0
isaacy2012 Jan 28, 2024
3920333
Fix checked_pow function
isaacy2012 Jan 29, 2024
c715a8b
Use repeater trick for tuple_repeated
isaacy2012 Jan 29, 2024
083bfa3
Add braces around if statement
isaacy2012 Jan 29, 2024
7461234
Replace auto&& with auto& in get_base
isaacy2012 Jan 29, 2024
e6a9464
Remove const_like_t in requirements for cartesian_base functions
isaacy2012 Jan 29, 2024
b3717cd
Remove const_like_t definition and further remove from requires clauses
isaacy2012 Jan 29, 2024
398f9aa
Remove const_like_t
isaacy2012 Jan 29, 2024
a238d07
Move requires clauses to end of function declaration
isaacy2012 Jan 29, 2024
089a98d
Fix indentation
isaacy2012 Jan 29, 2024
4d2b7ae
Remove cartesian_product_repeat_n_fn test
isaacy2012 Jan 29, 2024
397a5e0
Return empty sequence when PowN is 0 fo cartesian_power and cartesian…
isaacy2012 Jan 29, 2024
f00eeaa
Add tests for cartesian_power for PowN 0 and 1
isaacy2012 Jan 29, 2024
193c31e
Merge branch 'main' into feat/cartesian-product-and-with
isaacy2012 Jan 29, 2024
be44189
Update test/test_cartesian_power.cpp
isaacy2012 Jan 29, 2024
00a36ff
Add includes requirements header to adjacent.hpp
isaacy2012 Jan 29, 2024
07cacf2
Fix export location for cartesian_power
isaacy2012 Jan 29, 2024
39ead1d
Fix FLUX_EXPORT for cartesian_power_map
isaacy2012 Jan 29, 2024
91903c2
Refactor cartesian_product_adaptor and traits ordering
isaacy2012 Jan 29, 2024
01fad2d
Reuse flux::first(self.base_) in cartesian_traits_base_impl::first
isaacy2012 Jan 29, 2024
6f6af8e
Merge branch 'feat/cartesian-product-and-with' of https://github.com/…
isaacy2012 Jan 29, 2024
1902bb8
Rename cartesian_power and cartesian_power_map to cartesian_product_r…
isaacy2012 Jan 29, 2024
b8b59f0
Replace require_single_type with static_assert
isaacy2012 Jan 29, 2024
41987b0
Revert "Rename cartesian_power and cartesian_power_map to cartesian_p…
isaacy2012 Jan 29, 2024
5d6ff3a
Restore alphabetical order for test_cartesian_power and test_cartesia…
isaacy2012 Jan 30, 2024
4f02c0d
Swap order of Base and Func for cartesian_power_map
isaacy2012 Jan 30, 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
5 changes: 4 additions & 1 deletion include/flux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
#include <flux/op/all_any_none.hpp>
#include <flux/op/begin_end.hpp>
#include <flux/op/cache_last.hpp>
#include <flux/op/cartesian_base.hpp>
#include <flux/op/cartesian_power.hpp>
#include <flux/op/cartesian_power_map.hpp>
#include <flux/op/cartesian_product.hpp>
#include <flux/op/cartesian_product_with.hpp>
#include <flux/op/cartesian_product_map.hpp>
#include <flux/op/chain.hpp>
#include <flux/op/chunk.hpp>
#include <flux/op/chunk_by.hpp>
Expand Down
14 changes: 14 additions & 0 deletions include/flux/core/numeric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,20 @@ inline constexpr auto checked_mul =
}
};

FLUX_EXPORT
inline constexpr auto checked_pow =
[]<std::signed_integral T, std::unsigned_integral U>(T base, U exponent,
std::source_location loc = std::source_location::current())
-> T
{
T res{1};
for(U i{0}; i < exponent; i++) {
res = checked_mul(res, base, loc);
}
return res;
};


inline constexpr auto checked_div =
[]<std::signed_integral T>(T lhs, T rhs,
std::source_location loc = std::source_location::current())
Expand Down
18 changes: 3 additions & 15 deletions include/flux/op/adjacent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <flux/op/begin_end.hpp>
#include <flux/op/reverse.hpp>
#include <flux/op/requirements.hpp>
#include <flux/op/zip.hpp>
#include <flux/source/iota.hpp>

Expand Down Expand Up @@ -176,19 +177,6 @@ struct adjacent_adaptor : inline_sequence_base<adjacent_adaptor<Base, N>> {
};
};

template <typename Func, typename E, distance_t N>
struct adjacent_invocable_helper {
template <std::size_t I>
using repeater = E;

static inline constexpr bool value = []<std::size_t... Is> (std::index_sequence<Is...>) consteval {
return std::regular_invocable<Func, repeater<Is>...>;
}(std::make_index_sequence<N>{});
};

template <typename Func, typename E, distance_t N>
concept adjacent_invocable = adjacent_invocable_helper<Func, E, N>::value;

template <typename Base, distance_t N, typename Func>
struct adjacent_map_adaptor : inline_sequence_base<adjacent_map_adaptor<Base, N, Func>> {
private:
Expand All @@ -207,7 +195,7 @@ struct adjacent_map_adaptor : inline_sequence_base<adjacent_map_adaptor<Base, N,
template <typename Self>
static constexpr auto read_at(Self& self, cursor_t<Self> const& cur)
-> decltype(auto)
requires adjacent_invocable<decltype((self.func_)), element_t<decltype((self.base_))>, N>
requires repeated_invocable<decltype((self.func_)), element_t<decltype((self.base_))>, N>
{
return std::apply([&](auto const&... curs) {
return std::invoke(self.func_, flux::read_at(self.base_, curs)...);
Expand All @@ -231,7 +219,7 @@ template <distance_t N>
struct adjacent_map_fn {
template <adaptable_sequence Seq, typename Func>
requires multipass_sequence<Seq> &&
adjacent_invocable<Func, element_t<Seq>, N>
repeated_invocable<Func, element_t<Seq>, N>
[[nodiscard]]
constexpr auto operator()(Seq&& seq, Func func) const -> multipass_sequence auto
{
Expand Down
Loading
Loading