Skip to content

Commit

Permalink
Rename strict_weak_order_for to weak_ordering_for
Browse files Browse the repository at this point in the history
  • Loading branch information
tcbrindle committed Feb 1, 2024
1 parent 20c0d98 commit a010b3e
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 42 deletions.
12 changes: 6 additions & 6 deletions docs/reference/adaptors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ You can pass a reference to a sequence into an adaptor using :func:`flux::ref` o

.. function::
template <sequence Seq1, sequence Seq2, typename Cmp = std::compare_three_way> \
requires strict_weak_order_for<Cmp, Seq1> && strict_weak_order_for<Cmp, Seq2> \
requires weak_ordering_for<Cmp, Seq1> && weak_ordering_for<Cmp, Seq2> \
auto set_difference(Seq1 seq1, Seq2 seq2, Cmp cmp = {}) -> sequence auto;

Returns a sequence adaptor which yields the set difference of the two input sequences :var:`seq1` and :var:`seq2`, ordered by the given comparison function :var:`cmp`.
Expand Down Expand Up @@ -1180,7 +1180,7 @@ You can pass a reference to a sequence into an adaptor using :func:`flux::ref` o

.. function::
template <sequence Seq1, sequence Seq2, typename Cmp = std::compare_three_way> \
requires strict_weak_order_for<Cmp, Seq1> && strict_weak_order_for<Cmp, Seq2> \
requires weak_ordering_for<Cmp, Seq1> && weak_ordering_for<Cmp, Seq2> \
auto set_intersection(Seq1 seq1, Seq2 seq2, Cmp cmp = {}) -> sequence auto;

Returns a sequence adaptor which yields the set intersection of the two input sequences :var:`seq1` and :var:`seq2`, ordered by the given comparison function :var:`cmp`.
Expand Down Expand Up @@ -1259,8 +1259,8 @@ You can pass a reference to a sequence into an adaptor using :func:`flux::ref` o
std::common_reference_with<element_t<Seq1>, element_t<Seq2>> &&
std::common_reference_with<rvalue_element_t<Seq1>, rvalue_element_t<Seq2>> &&
requires { typename std::common_type_t<value_t<Seq1>, value_t<Seq2>>; } &&
strict_weak_order_for<Cmp, Seq1> &&
strict_weak_order_for<Cmp, Seq2>
weak_ordering_for<Cmp, Seq1> &&
weak_ordering_for<Cmp, Seq2>

:param seq1: The first sequence to merge.
:param seq2: The second sequence to merge.
Expand Down Expand Up @@ -1328,8 +1328,8 @@ You can pass a reference to a sequence into an adaptor using :func:`flux::ref` o
std::common_reference_with<element_t<Seq1>, element_t<Seq2>> &&
std::common_reference_with<rvalue_element_t<Seq1>, rvalue_element_t<Seq2>> &&
requires { typename std::common_type_t<value_t<Seq1>, value_t<Seq2>>; } &&
strict_weak_order_for<Cmp, Seq1> &&
strict_weak_order_for<Cmp, Seq2>
weak_ordering_for<Cmp, Seq1> &&
weak_ordering_for<Cmp, Seq2>
:param seq1: The first sorted sequence to merge.
:param seq2: The second sorted sequence to merge.
Expand Down
12 changes: 6 additions & 6 deletions docs/reference/algorithms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ Algorithms
------------

.. function::
template <multipass_sequence Seq, strict_weak_order_for<Seq> Cmp = std::compare_three_way> \
template <multipass_sequence Seq, weak_ordering_for<Seq> Cmp = std::compare_three_way> \
auto find_max(Seq&& seq, Cmp cmp = {}) -> cursor_t<Seq>;

Returns a cursor to the maximum element of :var:`seq`, compared using :var:`cmp`.
Expand Down Expand Up @@ -380,7 +380,7 @@ Algorithms
------------

.. function::
template <multipass_sequence Seq, strict_weak_order_for<Seq> Cmp = std::compare_three_way> \
template <multipass_sequence Seq, weak_ordering_for<Seq> Cmp = std::compare_three_way> \
auto find_min(Seq&& seq, Cmp cmp = {}) -> cursor_t<Seq>;

Returns a cursor to the minimum element of :var:`seq`, compared using :var:`cmp`.
Expand Down Expand Up @@ -409,7 +409,7 @@ Algorithms
---------------

.. function::
template <multipass_sequence Seq, strict_weak_order_for<Seq> Cmp = std::compare_three_way> \
template <multipass_sequence Seq, weak_ordering_for<Seq> Cmp = std::compare_three_way> \
auto find_minmax(Seq&& seq, Cmp cmp = {}) -> minmax_result<cursor_t<Seq>>;

Returns a pair of cursors to the minimum and maximum elements of :var:`seq`, compared using :var:`cmp`.
Expand Down Expand Up @@ -489,14 +489,14 @@ Algorithms
-------

.. function::
template <sequence Seq, strict_weak_order_for<Seq> Cmp = std::compare_three_way> \
template <sequence Seq, weak_ordering_for<Seq> Cmp = std::compare_three_way> \
auto max(Seq&& seq, Cmp cmp = {}) -> optional<value_t<Seq>>;

``min``
-------

.. function::
template <sequence Seq, strict_weak_order_for<Seq> Cmp = std::compare_three_way> \
template <sequence Seq, weak_ordering_for<Seq> Cmp = std::compare_three_way> \
requires std::predicate<Cmp&, value_t<Seq>, element_t<Seq>> \
auto min(Seq&& seq, Cmp cmp = {}) -> optional<value_t<Seq>>;

Expand All @@ -506,7 +506,7 @@ Algorithms
.. struct:: template <typename T> minmax_result;

.. function::
template <sequence Seq, strict_weak_order_for<Seq> Cmp = std::compare_three_way> \
template <sequence Seq, weak_ordering_for<Seq> Cmp = std::compare_three_way> \
requires std::predicate<Cmp&, value_t<Seq>, element_t<Seq>> \
auto minmax(Seq&& seq, Cmp cmp = {}) -> optional<minmax_result<Seq>>;

Expand Down
85 changes: 85 additions & 0 deletions docs/reference/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,88 @@ Concepts

.. concept::
template <typename Seq, typename T> writable_sequence_of

A sequence :var:`Seq` models :expr:`writable_sequence_t<Seq, T>` for a type :var:`T` if :expr:`element_t<Seq>` is assignable from an object of type :var:`T`.

The :concept:`writable_sequence_of` concept is defined as::

template <typename Seq, typename T>
concept writable_sequence_of =
sequence<Seq> &&
requires (element_t<Seq> e, T&& item) {
{ e = std::forward<T>(item) } -> std::same_as<element_t<Seq>&>;
};

``element_swappable_with``
--------------------------

.. concept::
template <typename Seq1, typename Seq2> element_swappable_with

A pair of sequences :var:`Seq1` and :var:`Seq2` model :concept:`element_swappable_with` if their respective elements can be swapped, that is, we can assign to an element of :var:`Seq1` from an rvalue element of :var:`Seq2` and vice-versa.

Formally, the :concept:`element_swappable_with` concept is defined as::

template <typename Seq1, typename Seq2>
concept element_swappable_with =
std::constructible_from<value_t<Seq1>, rvalue_element_t<Seq1>> &&
std::constructible_from<value_t<Seq2>, rvalue_element_t<Seq2>> &&
writable_sequence_of<Seq1, rvalue_element_t<Seq2>> &&
writable_sequence_of<Seq1, value_t<Seq2>&&> &&
writable_sequence_of<Seq2, rvalue_element_t<Seq1>> &&
writable_sequence_of<Seq2, value_t<Seq1>&&>;


``ordering_invocable``
----------------------

.. concept::
template <typename Fn, typename T, typename U, typename Cat = std::partial_ordering> \
ordering_invocable

The concept :concept:`ordering_invocable` signifies that the binary invocable :var:`Fn` return a value of one of the standard comparison categories, convertible to :var:`Cat`, for all combinations of arguments of types :var:`T` and :var:`U`

Semantic requirements:

* Let :expr:`r1 = fn(a, b)` and :expr:`r2 = fn(b, c)`. If :expr:`r1 == r2` and :expr:`r1 != std::partial_ordering::unordered`, then :expr:`fn(a, c) == r1`.
* :expr:`fn(a, b) == std::partial_ordering::less` if and only if :expr:`fn(b, a) == std::partial_ordering::greater`

The :concept:`ordering_invocable` concept is defined as::

template <typename Fn, typename T, typename U, typename Cat>
concept ordering_invocable_ = // exposition-only
std::regular_invocable<Fn, T, U> &&
std::same_as<
std::common_comparison_category_t<std::decay_t<std::invoke_result_t<Fn, T, U>>>,
Cat>,
Cat>;

template <typename Fn, typename T, typename U, typename Cat = std::partial_ordering>
concept ordering_invocable =
ordering_invocable_<Fn, T, U, Cat> &&
ordering_invocable_<Fn, U, T, Cat> &&
ordering_invocable_<Fn, T, T, Cat> &&
ordering_invocable_<Fn, U, U, Cat>;


``weak_ordering_for``
----------------------------

.. concept::
template <typename Fn, typename Seq1, typename Seq2 = Seq1> \
weak_ordering_for

Signifies that a binary callable :var:`Fn` forms a strict weak order over the elements of sequences :var:`Seq1` and :var:`Seq2`.

It is defined as::

template <typename Fn, typename Seq1, typename Seq2 = Seq1>
concept weak_ordering_for =
sequence<Seq1> &&
sequence<Seq2> &&
ordering_invocable<Fn&, element_t<Seq1>, element_t<Seq2>, std::weak_ordering> &&
ordering_invocable<Fn&, value_t<Seq1>&, element_t<Seq2>, std::weak_ordering> &&
ordering_invocable<Fn&, element_t<Seq1>, value_t<Seq2>&, std::weak_ordering> &&
ordering_invocable<Fn&, value_t<Seq1>&, value_t<Seq2>&, std::weak_ordering> &&
ordering_invocable<Fn&, common_element_t<Seq1>, common_element_t<Seq2>, std::weak_ordering>;

14 changes: 7 additions & 7 deletions include/flux/core/inline_sequence_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,17 +409,17 @@ struct inline_sequence_base {
constexpr auto find_if_not(Pred pred);

template <typename Cmp = std::compare_three_way>
requires strict_weak_order_for<Cmp, Derived>
requires weak_ordering_for<Cmp, Derived>
[[nodiscard]]
constexpr auto find_max(Cmp cmp = Cmp{});

template <typename Cmp = std::compare_three_way>
requires strict_weak_order_for<Cmp, Derived>
requires weak_ordering_for<Cmp, Derived>
[[nodiscard]]
constexpr auto find_min(Cmp cmp = Cmp{});

template <typename Cmp = std::compare_three_way>
requires strict_weak_order_for<Cmp, Derived>
requires weak_ordering_for<Cmp, Derived>
[[nodiscard]]
constexpr auto find_minmax(Cmp cmp = Cmp{});

Expand Down Expand Up @@ -448,15 +448,15 @@ struct inline_sequence_base {
detail::element_swappable_with<Derived, Derived>;

template <typename Cmp = std::compare_three_way>
requires strict_weak_order_for<Cmp, Derived>
requires weak_ordering_for<Cmp, Derived>
constexpr auto max(Cmp cmp = Cmp{});

template <typename Cmp = std::compare_three_way>
requires strict_weak_order_for<Cmp, Derived>
requires weak_ordering_for<Cmp, Derived>
constexpr auto min(Cmp cmp = Cmp{});

template <typename Cmp = std::compare_three_way>
requires strict_weak_order_for<Cmp, Derived>
requires weak_ordering_for<Cmp, Derived>
constexpr auto minmax(Cmp cmp = Cmp{});

template <typename Pred>
Expand All @@ -477,7 +477,7 @@ struct inline_sequence_base {
requires random_access_sequence<Derived> &&
bounded_sequence<Derived> &&
detail::element_swappable_with<Derived, Derived> &&
strict_weak_order_for<Cmp, Derived>
weak_ordering_for<Cmp, Derived>
constexpr void sort(Cmp cmp = {});

constexpr auto product()
Expand Down
12 changes: 6 additions & 6 deletions include/flux/op/find_min_max.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace detail {

struct find_min_fn {
template <multipass_sequence Seq,
strict_weak_order_for<Seq> Cmp = std::compare_three_way>
weak_ordering_for<Seq> Cmp = std::compare_three_way>
[[nodiscard]]
constexpr auto operator()(Seq&& seq, Cmp cmp = {}) const -> cursor_t<Seq>
{
Expand All @@ -34,7 +34,7 @@ struct find_min_fn {

struct find_max_fn {
template <multipass_sequence Seq,
strict_weak_order_for<Seq> Cmp = std::compare_three_way>
weak_ordering_for<Seq> Cmp = std::compare_three_way>
[[nodiscard]]
constexpr auto operator()(Seq&& seq, Cmp cmp = {}) const -> cursor_t<Seq>
{
Expand All @@ -53,7 +53,7 @@ struct find_max_fn {

struct find_minmax_fn {
template <multipass_sequence Seq,
strict_weak_order_for<Seq> Cmp = std::compare_three_way>
weak_ordering_for<Seq> Cmp = std::compare_three_way>
[[nodiscard]]
constexpr auto operator()(Seq&& seq, Cmp cmp = {}) const
-> minmax_result<cursor_t<Seq>>
Expand Down Expand Up @@ -85,23 +85,23 @@ FLUX_EXPORT inline constexpr auto find_minmax = detail::find_minmax_fn{};

template <typename D>
template <typename Cmp>
requires strict_weak_order_for<Cmp, D>
requires weak_ordering_for<Cmp, D>
constexpr auto inline_sequence_base<D>::find_min(Cmp cmp)
{
return flux::find_min(derived(), std::move(cmp));
}

template <typename D>
template <typename Cmp>
requires strict_weak_order_for<Cmp, D>
requires weak_ordering_for<Cmp, D>
constexpr auto inline_sequence_base<D>::find_max(Cmp cmp)
{
return flux::find_max(derived(), std::move(cmp));
}

template <typename D>
template <typename Cmp>
requires strict_weak_order_for<Cmp, D>
requires weak_ordering_for<Cmp, D>
constexpr auto inline_sequence_base<D>::find_minmax(Cmp cmp)
{
return flux::find_minmax(derived(), std::move(cmp));
Expand Down
12 changes: 6 additions & 6 deletions include/flux/op/minmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct minmax_result {
namespace detail {

struct min_op {
template <sequence Seq, strict_weak_order_for<Seq> Cmp = std::compare_three_way>
template <sequence Seq, weak_ordering_for<Seq> Cmp = std::compare_three_way>
[[nodiscard]]
constexpr auto operator()(Seq&& seq, Cmp cmp = Cmp{}) const
-> flux::optional<value_t<Seq>>
Expand All @@ -39,7 +39,7 @@ struct min_op {
};

struct max_op {
template <sequence Seq, strict_weak_order_for<Seq> Cmp = std::compare_three_way>
template <sequence Seq, weak_ordering_for<Seq> Cmp = std::compare_three_way>
[[nodiscard]]
constexpr auto operator()(Seq&& seq, Cmp cmp = Cmp{}) const
-> flux::optional<value_t<Seq>>
Expand All @@ -55,7 +55,7 @@ struct max_op {
};

struct minmax_op {
template <sequence Seq, strict_weak_order_for<Seq> Cmp = std::compare_three_way>
template <sequence Seq, weak_ordering_for<Seq> Cmp = std::compare_three_way>
[[nodiscard]]
constexpr auto operator()(Seq&& seq, Cmp cmp = Cmp{}) const
-> flux::optional<minmax_result<value_t<Seq>>>
Expand Down Expand Up @@ -93,23 +93,23 @@ FLUX_EXPORT inline constexpr auto minmax = detail::minmax_op{};

template <typename Derived>
template <typename Cmp>
requires strict_weak_order_for<Cmp, Derived>
requires weak_ordering_for<Cmp, Derived>
constexpr auto inline_sequence_base<Derived>::max(Cmp cmp)
{
return flux::max(derived(), std::move(cmp));
}

template <typename Derived>
template <typename Cmp>
requires strict_weak_order_for<Cmp, Derived>
requires weak_ordering_for<Cmp, Derived>
constexpr auto inline_sequence_base<Derived>::min(Cmp cmp)
{
return flux::min(derived(), std::move(cmp));
}

template <typename Derived>
template <typename Cmp>
requires strict_weak_order_for<Cmp, Derived>
requires weak_ordering_for<Cmp, Derived>
constexpr auto inline_sequence_base<Derived>::minmax(Cmp cmp)
{
return flux::minmax(derived(), std::move(cmp));
Expand Down
2 changes: 1 addition & 1 deletion include/flux/op/requirements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ concept foldable =

FLUX_EXPORT
template <typename Fn, typename Seq1, typename Seq2 = Seq1>
concept strict_weak_order_for =
concept weak_ordering_for =
sequence<Seq1> &&
sequence<Seq2> &&
ordering_invocable<Fn&, element_t<Seq1>, element_t<Seq2>, std::weak_ordering> &&
Expand Down
16 changes: 8 additions & 8 deletions include/flux/op/set_adaptors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,8 @@ concept set_op_compatible =
struct set_union_fn {
template <adaptable_sequence Seq1, adaptable_sequence Seq2, typename Cmp = std::compare_three_way>
requires set_op_compatible<Seq1, Seq2> &&
strict_weak_order_for<Cmp, Seq1> &&
strict_weak_order_for<Cmp, Seq2>
weak_ordering_for<Cmp, Seq1> &&
weak_ordering_for<Cmp, Seq2>
[[nodiscard]]
constexpr auto operator()(Seq1&& seq1, Seq2&& seq2, Cmp cmp = {}) const
{
Expand All @@ -516,8 +516,8 @@ struct set_union_fn {

struct set_difference_fn {
template <adaptable_sequence Seq1, adaptable_sequence Seq2, typename Cmp = std::compare_three_way>
requires strict_weak_order_for<Cmp, Seq1> &&
strict_weak_order_for<Cmp, Seq2>
requires weak_ordering_for<Cmp, Seq1> &&
weak_ordering_for<Cmp, Seq2>
[[nodiscard]]
constexpr auto operator()(Seq1&& seq1, Seq2&& seq2, Cmp cmp = {}) const
{
Expand All @@ -528,8 +528,8 @@ struct set_difference_fn {
struct set_symmetric_difference_fn {
template <adaptable_sequence Seq1, adaptable_sequence Seq2, typename Cmp = std::compare_three_way>
requires set_op_compatible<Seq1, Seq2> &&
strict_weak_order_for<Cmp, Seq1> &&
strict_weak_order_for<Cmp, Seq2>
weak_ordering_for<Cmp, Seq1> &&
weak_ordering_for<Cmp, Seq2>
[[nodiscard]]
constexpr auto operator()(Seq1&& seq1, Seq2&& seq2, Cmp cmp = {}) const
{
Expand All @@ -539,8 +539,8 @@ struct set_symmetric_difference_fn {

struct set_intersection_fn {
template <adaptable_sequence Seq1, adaptable_sequence Seq2, typename Cmp = std::compare_three_way>
requires strict_weak_order_for<Cmp, Seq1> &&
strict_weak_order_for<Cmp, Seq2>
requires weak_ordering_for<Cmp, Seq1> &&
weak_ordering_for<Cmp, Seq2>
[[nodiscard]]
constexpr auto operator()(Seq1&& seq1, Seq2&& seq2, Cmp cmp = {}) const
{
Expand Down
Loading

0 comments on commit a010b3e

Please sign in to comment.