Skip to content

Commit

Permalink
Apply P0663 PR for Issue 155: Comparison concepts and reference types
Browse files Browse the repository at this point in the history
Fixes #155; partially addresses #330.
Depends on #167.
  • Loading branch information
CaseyCarter committed Jul 17, 2017
1 parent 5e25f68 commit 1f5d72e
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Casey's WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Apply P0663 PR for Issue 155: Comparison concepts and reference types

Fixes #155.
Fixes #155; partially addresses #330.

### P0740 "Ranges TS 'Immediate' Issues from Toronto"
* 167 `ConvertibleTo` should require both implicit and explicit conversion; also fixes #314
Expand Down
144 changes: 83 additions & 61 deletions concepts.tex
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,12 @@

template <class T, class U>
concept bool Swappable() {
return Swappable<T>() &&
return
Swappable<T>() &&
Swappable<U>() &&
CommonReference<const T&, const U&>() &&
CommonReference<
const remove_reference_t<T>&,
const remove_reference_t<U>&>() &&
requires(T&& t, U&& u) {
ranges::swap(std::forward<T>(t), std::forward<U>(u));
ranges::swap(std::forward<U>(u), std::forward<T>(t));
Expand Down Expand Up @@ -693,34 +696,32 @@
\begin{itemdecl}
template <class B>
concept bool Boolean() {
return MoveConstructible<B>() && // (see \ref{concepts.lib.object.moveconstructible})
requires(const B b1, const B b2, const bool a) {
bool(b1);
{ b1 } -> bool;
bool(!b1);
{ !b1 } -> bool;
{ b1 && b2 } -> Same<bool>;
{ b1 && a } -> Same<bool>;
{ a && b1 } -> Same<bool>;
{ b1 || b2 } -> Same<bool>;
{ b1 || a } -> Same<bool>;
{ a || b1 } -> Same<bool>;
{ b1 == b2 } -> bool;
{ b1 != b2 } -> bool;
{ b1 == a } -> bool;
{ a == b1 } -> bool;
{ b1 != a } -> bool;
{ a != b1 } -> bool;
return Movable<decay_t<B>>() && // (see \ref{concepts.lib.object.movable})
requires(const remove_reference_t<B>& b1,
const remove_reference_t<B>& b2, const bool a) {
{ b1 } -> ConvertibleTo<bool>&&;
{ !b1 } -> ConvertibleTo<bool>&&;
{ b1 && a } -> Same<bool>&&;
{ b1 || a } -> Same<bool>&&;
{ b1 && b2 } -> Same<bool>&&;
{ a && b2 } -> Same<bool>&&;
{ b1 || b2 } -> Same<bool>&&;
{ a || b2 } -> Same<bool>&&;
{ b1 == b2 } -> ConvertibleTo<bool>&&;
{ b1 == a } -> ConvertibleTo<bool>&&;
{ a == b2 } -> ConvertibleTo<bool>&&;
{ b1 != b2 } -> ConvertibleTo<bool>&&;
{ b1 != a } -> ConvertibleTo<bool>&&;
{ a != b2 } -> ConvertibleTo<bool>&&;
};
}
\end{itemdecl}

\pnum
Given values \tcode{b1} and \tcode{b2} of type \tcode{B}, then
\tcode{Boolean<B>()} is satisfied if and only if
Given \tcode{const} lvalues \tcode{b1} and \tcode{b2} of type
\tcode{remove_reference_t<B>}, then \tcode{Boolean<B>()} is satisfied only if

\begin{itemize}
\item \tcode{bool(b1) == [](bool x) \{ return x; \}(b1)}.
\item \tcode{bool(b1) == !bool(!b1)}.
\item \tcode{(b1 \&\& b2)}, \tcode{(b1 \&\& bool(b2))}, and
\tcode{(bool(b1) \&\& b2)} are all equal to
Expand All @@ -745,19 +746,21 @@
\begin{itemdecl}
template <class T, class U>
concept bool WeaklyEqualityComparable() {
return requires(const T& t, const U& u) {
{ t == u } -> Boolean;
{ u == t } -> Boolean;
{ t != u } -> Boolean;
{ u != t } -> Boolean;
return requires(const remove_reference_t<T>& t,
const remove_reference_t<U>& u) {
{ t == u } -> Boolean&&;
{ t != u } -> Boolean&&;
{ u == t } -> Boolean&&;
{ u != t } -> Boolean&&;
};
}
\end{itemdecl}

\begin{itemdescr}
\pnum
Let \tcode{t} and \tcode{u} be objects of types \tcode{T} and \tcode{U} respectively.
\tcode{WeaklyEqualityComparable<T, U>()} is satisfied if and only if:
Let \tcode{t} and \tcode{u} be \tcode{const} lvalues of types
\tcode{remove_reference_t<T>} and \tcode{remove_reference_t<U>}.
\tcode{Weakly\-Equality\-Comparable<T, U>()} is satisfied if and only if:
\begin{itemize}
\item \tcode{t == u}, \tcode{u == t}, \tcode{t != u}, and \tcode{u != t}
have the same domain.
Expand Down Expand Up @@ -794,19 +797,25 @@
\begin{itemdecl}
template <class T, class U>
concept bool EqualityComparable() {
return CommonReference<const T&, const U&>() &&
return
EqualityComparable<T>() &&
EqualityComparable<U>() &&
CommonReference<
const remove_reference_t<T>&,
const remove_reference_t<U>&>() &&
EqualityComparable<
remove_cv_t<remove_reference_t<common_reference_t<const T&, const U&>>>>() &&
common_reference_t<
const remove_reference_t<T>&,
const remove_reference_t<U>&>>() &&
WeaklyEqualityComparable<T, U>();
}
\end{itemdecl}

\begin{itemdescr}
\pnum
Let \tcode{t} be an object of type \tcode{T}, \tcode{u} be an object of type \tcode{U}, and \tcode{C} be
\tcode{common_reference_t<const T\&, const U\&>}.
Let \tcode{a} be a \tcode{const} lvalue of type \tcode{remove_reference_t<T>}, \tcode{b} be a
\tcode{const} lvalue of type \tcode{remove_reference_t<U>}, and \tcode{C} be
\tcode{common_reference_t<const remove_reference_t<T>\&, const remove_reference_t<U>\&>}.
Then \tcode{EqualityComparable<T, U>()}
is satisfied if and only if:

Expand All @@ -822,18 +831,19 @@
template <class T>
concept bool StrictTotallyOrdered() {
return EqualityComparable<T>() &&
requires(const T a, const T b) {
{ a < b } -> Boolean;
{ a > b } -> Boolean;
{ a <= b } -> Boolean;
{ a >= b } -> Boolean;
requires(const remove_reference_t<T>& t,
const remove_reference_t<U>& u) {
{ a < b } -> Boolean&&;
{ a > b } -> Boolean&&;
{ a <= b } -> Boolean&&;
{ a >= b } -> Boolean&&;
};
}
\end{itemdecl}

\begin{itemdescr}
\pnum
Let \tcode{a}, \tcode{b}, and \tcode{c} be objects of type \tcode{T}.
Let \tcode{a}, \tcode{b}, and \tcode{c} be \tcode{const} lvalues of type \tcode{remove_reference_t<T>}.
Then \tcode{StrictTotallyOrdered<T>()} is satisfied if and only if

\begin{itemize}
Expand All @@ -851,30 +861,37 @@
\begin{itemdecl}
template <class T, class U>
concept bool StrictTotallyOrdered() {
return CommonReference<const T&, const U&>() &&
return
StrictTotallyOrdered<T>() &&
StrictTotallyOrdered<U>() &&
CommonReference<
const remove_reference_t<T>&,
const remove_reference_t<U>&>() &&
StrictTotallyOrdered<
remove_cv_t<remove_reference_t<common_reference_t<const T&, const U&>>>>() &&
common_reference_t<
const remove_reference_t<T>&,
const remove_reference_t<U>&>>() &&
EqualityComparable<T, U>() &&
requires(const T t, const U u) {
{ t < u } -> Boolean;
{ t > u } -> Boolean;
{ t <= u } -> Boolean;
{ t >= u } -> Boolean;
{ u < t } -> Boolean;
{ u > t } -> Boolean;
{ u <= t } -> Boolean;
{ u >= t } -> Boolean;
requires(const remove_reference_t<T>& t,
const remove_reference_t<U>& u) {
{ t < u } -> Boolean&&;
{ t > u } -> Boolean&&;
{ t <= u } -> Boolean&&;
{ t >= u } -> Boolean&&;
{ u < t } -> Boolean&&;
{ u > t } -> Boolean&&;
{ u <= t } -> Boolean&&;
{ u >= t } -> Boolean&&;
};
}
\end{itemdecl}

\begin{itemdescr}
\pnum
Let \tcode{t} be an object of type T, \tcode{u} be an object
of type \tcode{U}, and \tcode{C} be
\tcode{common_reference_t<const T\&, const U\&>}.
Let \tcode{t} be a \tcode{const} lvalue of type \tcode{remove_reference_t<T>},
\tcode{u} be a \tcode{const} lvalue of type \tcode{remove_reference_t<U>},
and \tcode{C} be \tcode{common_reference_t<const remove_reference_t<T>\&,
const remove_reference_t<U>\&>}.
Then \tcode{StrictTotallyOrdered<T, U>()} is satisfied if and only if

\begin{itemize}
Expand Down Expand Up @@ -1180,22 +1197,27 @@

template <class R, class T, class U>
concept bool Relation() {
return Relation<R, T>() &&
return
Relation<R, T>() &&
Relation<R, U>() &&
CommonReference<const T&, const U&>() &&
CommonReference<
const remove_reference_t<T>&,
const remove_reference_t<U>&>() &&
Relation<R,
common_reference_t<const T&, const U&>>() &&
common_reference_t<
const remove_reference_t<T>&,
const remove_reference_t<U>&>>() &&
Predicate<R, T, U>() &&
Predicate<R, U, T>();
}
\end{itemdecl}

\begin{itemdescr}
\pnum
Let \tcode{r} be any object of type \tcode{R}, \tcode{t} be any
object of type \tcode{T}, \tcode{u} be any
object of type \tcode{U}, and \tcode{C} be
\tcode{common_reference_t<const T\&, const U\&>}.
Let \tcode{r} be an expression such that \tcode{decltype((r))} is \tcode{R},
\tcode{a} be an expression such that \tcode{decltype((a))} is \tcode{T},
and \tcode{C} be \tcode{common_reference_t<const remove_reference_t<T>\&,
const remove_reference_t<U>\&>}.
Then \tcode{Relation<R, T, U>()} is satisfied if and only if

\begin{itemize}
Expand Down

0 comments on commit 1f5d72e

Please sign in to comment.