Skip to content

Commit

Permalink
Rename cartesian_power and cartesian_power_map to cartesian_product_r…
Browse files Browse the repository at this point in the history
…epeat and cartesian_product_repeat_map
  • Loading branch information
isaacy2012 committed Jan 29, 2024
1 parent 6f6af8e commit 1902bb8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions include/flux.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#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_repeat.hpp>
#include <flux/op/cartesian_product_repeat_map.hpp>
#include <flux/op/cartesian_product.hpp>
#include <flux/op/cartesian_product_map.hpp>
#include <flux/op/chain.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef FLUX_OP_CARTESIAN_POWER_HPP_INCLUDED
#define FLUX_OP_CARTESIAN_POWER_HPP_INCLUDED
#ifndef FLUX_OP_CARTESIAN_PRODUCT_REPEAT_HPP_INCLUDED
#define FLUX_OP_CARTESIAN_PRODUCT_REPEAT_HPP_INCLUDED

#include <flux/core.hpp>
#include <flux/core/numeric.hpp>
Expand All @@ -20,13 +20,13 @@ namespace flux {
namespace detail {

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

public:
constexpr explicit cartesian_power_adaptor(Base&& base)
constexpr explicit cartesian_product_repeat_adaptor(Base&& base)
: base_(FLUX_FWD(base))
{}

Expand All @@ -42,7 +42,7 @@ struct cartesian_power_adaptor


template<std::size_t PowN>
struct cartesian_power_fn {
struct cartesian_product_repeat_fn {

template <adaptable_sequence Seq>
requires multipass_sequence<Seq>
Expand All @@ -52,7 +52,7 @@ struct cartesian_power_fn {
if constexpr(PowN == 0) {
return empty<std::tuple<>>;
} else {
return cartesian_power_adaptor<PowN, std::decay_t<Seq>>(
return cartesian_product_repeat_adaptor<PowN, std::decay_t<Seq>>(
FLUX_FWD(seq));
}
}
Expand All @@ -63,7 +63,7 @@ struct cartesian_power_fn {

FLUX_EXPORT
template<std::size_t PowN>
inline constexpr auto cartesian_power = detail::cartesian_power_fn<PowN>{};
inline constexpr auto cartesian_product_repeat = detail::cartesian_product_repeat_fn<PowN>{};

} // end namespace flux

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef FLUX_OP_CARTESIAN_POWER_MAP_HPP_INCLUDED
#define FLUX_OP_CARTESIAN_POWER_MAP_HPP_INCLUDED
#ifndef FLUX_OP_CARTESIAN_PRODUCT_REPEAT_MAP_HPP_INCLUDED
#define FLUX_OP_CARTESIAN_PRODUCT_REPEAT_MAP_HPP_INCLUDED

#include <flux/op/cartesian_base.hpp>
#include <flux/op/requirements.hpp>
Expand All @@ -14,14 +14,14 @@ namespace flux {
namespace detail {

template <std::size_t PowN, typename Func, sequence Base>
struct cartesian_power_map_adaptor
: inline_sequence_base<cartesian_power_map_adaptor<PowN, Func, Base>> {
struct cartesian_product_repeat_map_adaptor
: inline_sequence_base<cartesian_product_repeat_map_adaptor<PowN, Func, Base>> {
private:
FLUX_NO_UNIQUE_ADDRESS Base base_;
FLUX_NO_UNIQUE_ADDRESS Func func_;

public:
constexpr explicit cartesian_power_map_adaptor(decays_to<Func> auto&& func, decays_to<Base> auto&& base)
constexpr explicit cartesian_product_repeat_map_adaptor(decays_to<Func> auto&& func, decays_to<Base> auto&& base)
: base_(FLUX_FWD(base)),
func_(FLUX_FWD(func))
{}
Expand All @@ -36,7 +36,7 @@ struct cartesian_power_map_adaptor
};

template <std::size_t PowN>
struct cartesian_power_map_fn
struct cartesian_product_repeat_map_fn
{
template <typename Func, adaptable_sequence Seq>
requires multipass_sequence<Seq> &&
Expand All @@ -47,7 +47,7 @@ struct cartesian_power_map_fn
if constexpr(PowN == 0) {
return empty<std::invoke_result_t<Func>>;
} else {
return cartesian_power_map_adaptor<PowN, Func, std::decay_t<Seq>>(
return cartesian_product_repeat_map_adaptor<PowN, Func, std::decay_t<Seq>>(
std::move(func), FLUX_FWD(seq));
}
}
Expand All @@ -58,7 +58,7 @@ struct cartesian_power_map_fn
FLUX_EXPORT
template <distance_t N>
requires (N >= 0)
inline constexpr auto cartesian_power_map = detail::cartesian_power_map_fn<N>{};
inline constexpr auto cartesian_product_repeat_map = detail::cartesian_product_repeat_map_fn<N>{};

} // namespace flux

Expand Down
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ add_executable(test-flux
test_cache_last.cpp
test_cartesian_product.cpp
test_cartesian_product_map.cpp
test_cartesian_power.cpp
test_cartesian_power_map.cpp
test_cartesian_product_repeat.cpp
test_cartesian_product_repeat_map.cpp
test_chain.cpp
test_chunk.cpp
test_chunk_by.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@

namespace {

constexpr bool test_cartesian_power()
constexpr bool test_cartesian_product_repeat()
{
// cartesian_power<0> should be empty ( same as cartesian_product<>() )
// cartesian_product_repeat<0> should be empty ( same as cartesian_product<>() )
{
auto cart = flux::cartesian_power<0>(std::array{100, 200, 300});
auto cart = flux::cartesian_product_repeat<0>(std::array{100, 200, 300});
using C = decltype(cart);
static_assert(std::is_same_v<flux::value_t<C>, std::tuple<>>);

STATIC_CHECK(cart.is_empty());
}
// cartesian_power<1> should be the same as cartesian_product<T>()
// cartesian_product_repeat<1> should be the same as cartesian_product<T>()
{
auto cart = flux::cartesian_power<1>(std::array{100, 200, 300});
auto cart = flux::cartesian_product_repeat<1>(std::array{100, 200, 300});

using C = decltype(cart);

Expand Down Expand Up @@ -82,7 +82,7 @@ constexpr bool test_cartesian_power()

}
{
auto cart = flux::cartesian_power<2>(std::array{100, 200, 300});
auto cart = flux::cartesian_product_repeat<2>(std::array{100, 200, 300});

using C = decltype(cart);

Expand Down Expand Up @@ -148,7 +148,7 @@ constexpr bool test_cartesian_power()
}

{
auto prod = flux::cartesian_power<3>(std::array{'a', 'b', 'c', 'd'});
auto prod = flux::cartesian_product_repeat<3>(std::array{'a', 'b', 'c', 'd'});
static_assert(prod.size() == 64);

using C = decltype(prod);
Expand Down Expand Up @@ -259,11 +259,11 @@ constexpr bool test_cartesian_power()
return true;
}

static_assert(test_cartesian_power());
static_assert(test_cartesian_product_repeat());

}

TEST_CASE("cartesian power")
{
REQUIRE(test_cartesian_power());
REQUIRE(test_cartesian_product_repeat());
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ namespace {

constexpr auto sum = [](auto... args) { return (args + ...); };

constexpr bool test_cartesian_power_map()
constexpr bool test_cartesian_product_repeat_map()
{
// cartesian_power_map<0> should be empty ( same as cartesian_product<>() )
// cartesian_product_repeat_map<0> should be empty ( same as cartesian_product<>() )
{
auto make_0_1_pair = [](){ return std::make_pair(0, 1); };
auto cart = flux::cartesian_power_map<0>(make_0_1_pair, std::array{100, 200, 300});
auto cart = flux::cartesian_product_repeat_map<0>(make_0_1_pair, std::array{100, 200, 300});
using C = decltype(cart);
static_assert(std::is_same_v<flux::value_t<C>, std::pair<int, int>>);

STATIC_CHECK(cart.is_empty());
}
// cartesian_power_map<1> should same as map<T, F>()
// cartesian_product_repeat_map<1> should same as map<T, F>()
{
std::array arr1{100, 200};

constexpr auto square_individual = [](auto arg) { return arg * arg; };

auto cart = flux::cartesian_power_map<1>(square_individual, flux::ref(arr1));
auto cart = flux::cartesian_product_repeat_map<1>(square_individual, flux::ref(arr1));
using C = decltype(cart);

static_assert(flux::sequence<C>);
Expand Down Expand Up @@ -58,7 +58,7 @@ constexpr bool test_cartesian_power_map()
{
std::array arr1{100, 200};

auto cart = flux::cartesian_power_map<2>(sum, flux::ref(arr1));
auto cart = flux::cartesian_product_repeat_map<2>(sum, flux::ref(arr1));
using C = decltype(cart);

static_assert(flux::sequence<C>);
Expand Down Expand Up @@ -89,7 +89,7 @@ constexpr bool test_cartesian_power_map()
{
std::array arr1{1, 3};

auto cart = flux::cartesian_power_map<3>(sum, flux::ref(arr1));
auto cart = flux::cartesian_product_repeat_map<3>(sum, flux::ref(arr1));
using C = decltype(cart);

static_assert(flux::sequence<C>);
Expand Down Expand Up @@ -117,7 +117,7 @@ constexpr bool test_cartesian_power_map()
// Product with a zero-sized sequence works and produces an empty sequence
{
auto emp = flux::empty<int>;
auto cart = flux::cartesian_power_map<5>(sum, emp);
auto cart = flux::cartesian_product_repeat_map<5>(sum, emp);

static_assert(flux::bidirectional_sequence<decltype(cart)>);

Expand All @@ -133,7 +133,7 @@ constexpr bool test_cartesian_power_map()
double vals[3][3] = {};
auto get = [&vals](auto i, auto j) -> double& { return vals[i][j]; };

auto seq = flux::cartesian_power_map<2>(get, flux::iota(0, 3));
auto seq = flux::cartesian_product_repeat_map<2>(get, flux::iota(0, 3));

static_assert(std::same_as<flux::element_t<decltype(seq)>, double&>);

Expand All @@ -148,11 +148,11 @@ constexpr bool test_cartesian_power_map()

return true;
}
static_assert(test_cartesian_power_map());
static_assert(test_cartesian_product_repeat_map());

TEST_CASE("cartesian_power_map")
TEST_CASE("cartesian_product_repeat_map")
{
REQUIRE(test_cartesian_power_map());
REQUIRE(test_cartesian_product_repeat_map());
}

}

0 comments on commit 1902bb8

Please sign in to comment.