From 04ad290832790c6d2716fcabb20166f230a35c8e Mon Sep 17 00:00:00 2001 From: Jens Maurer Date: Thu, 17 Nov 2022 22:27:33 +0100 Subject: [PATCH] P2167R3 Improved Proposed Wording for LWG 2114 (contextually convertible to bool) Editorial notes: * Minor consistency fixes around the use of "each". * Some requested wording changes have already been applied as part of LWG 2114. Fixes NB US 073 (C++23 CD). --- source/algorithms.tex | 28 +++++++++++++++------------- source/containers.tex | 4 ++-- source/iterators.tex | 14 +++++--------- source/lib-intro.tex | 12 ++++++------ source/support.tex | 12 +++++++++--- source/threads.tex | 10 ++++++++-- source/utilities.tex | 13 +++++++++++-- 7 files changed, 56 insertions(+), 37 deletions(-) diff --git a/source/algorithms.tex b/source/algorithms.tex index ce678c8680..b76b4eefc2 100644 --- a/source/algorithms.tex +++ b/source/algorithms.tex @@ -151,13 +151,13 @@ whenever an algorithm expects a function object\iref{function.objects} that, when applied to the result of dereferencing the corresponding iterator, returns a value testable as \tcode{true}. -In other words, -if an algorithm takes \tcode{Predicate pred} as its argument and +If an algorithm takes \tcode{Predicate pred} as its argument and \tcode{first} as its iterator argument with value type \tcode{T}, -it should work correctly in the construct -\tcode{pred(*first)} contextually converted to \tcode{bool}\iref{conv}. +the expression \tcode{pred(*first)} shall be well-formed and +the type \tcode{decltype(pred(*first))} shall model +\exposconcept{boolean-testable}\iref{concept.booleantestable}. The function object \tcode{pred} shall not apply any non-constant function -through the dereferenced iterator. +through its argument. Given a glvalue \tcode{u} of type (possibly \keyword{const}) \tcode{T} that designates the same object as \tcode{*first}, \tcode{pred(u)} shall be a valid expression @@ -170,19 +170,21 @@ to dereferencing an iterator and type \tcode{T} when \tcode{T} is part of the signature, returns a value testable as \tcode{true}. -In other words, -if an algorithm takes \tcode{BinaryPredicate binary_pred} as its argument and +If an algorithm takes \tcode{BinaryPredicate binary_pred} as its argument and \tcode{first1} and \tcode{first2} as its iterator arguments with respective value types \tcode{T1} and \tcode{T2}, -it should work correctly in the construct -\tcode{binary_pred(*first1, *first2)} contextually converted to \tcode{bool}\iref{conv}. +the expression \tcode{binary_pred(*first1, *first2)} shall be well-formed and +the type \tcode{decltype(binary_pred(*first1, *first2))} shall model +\exposconcept{boolean-testable}. Unless otherwise specified, \tcode{BinaryPredicate} always takes the first iterator's \tcode{value_type} as its first argument, that is, in those cases when \tcode{T value} -is part of the signature, it should work correctly in the construct -\tcode{binary_pred(*first1, value)} contextually converted to \tcode{bool}\iref{conv}. +is part of the signature, +the expression \tcode{binary_pred(*first1, value)} shall be well-formed and +the type \tcode{decltype(binary_pred(*first1, value))} shall model +\exposconcept{boolean-testable}. \tcode{binary_pred} shall not apply any non-constant function -through the dereferenced iterators. +through any of its arguments. Given a glvalue \tcode{u} of type (possibly \keyword{const}) \tcode{T1} that designates the same object as \tcode{*first1}, and a glvalue \tcode{v} of type (possibly \keyword{const}) \tcode{T2} @@ -6569,7 +6571,7 @@ named \tcode{BinaryPredicate}~\iref{algorithms.requirements}. The return value of the function call operation applied to an object of type \tcode{Compare}, -when contextually converted to \tcode{bool}\iref{conv}, +when converted to \tcode{bool}, yields \tcode{true} if the first argument of the call is less than the second, and \tcode{false} otherwise. diff --git a/source/containers.tex b/source/containers.tex index ca670748d3..fd527681c8 100644 --- a/source/containers.tex +++ b/source/containers.tex @@ -425,7 +425,7 @@ \pnum \result -Convertible to \tcode{bool}. +\tcode{bool}. \pnum \returns @@ -536,7 +536,7 @@ \begin{itemdescr} \pnum \result -Convertible to \tcode{bool}. +\tcode{bool}. \pnum \returns diff --git a/source/iterators.tex b/source/iterators.tex index c803c4bb32..3c825621f8 100644 --- a/source/iterators.tex +++ b/source/iterators.tex @@ -2095,7 +2095,7 @@ & & \chdr{semantics} & \rhdr{pre-/post-condition} \\ \capsep \endhead \tcode{a != b} & - contextually convertible to \tcode{bool} & + \tcode{decltype(a != b)} models \exposconceptx{boolean-test\-able}{boolean-testable} & \tcode{!(a == b)} & \expects \orange{a}{b} is in the domain of \tcode{==}. \\ \rowsep @@ -2383,25 +2383,21 @@ \tcode{*(a + n)} & \\ \rowsep \tcode{a < b} & - contextually - convertible to \tcode{bool} & + \tcode{decltype(a < b)} models \exposconceptx{boolean-test\-able}{boolean-testable} & \effects Equivalent to: \tcode{return b - a > 0;} & \tcode{<} is a total ordering relation \\ \rowsep \tcode{a > b} & - contextually - convertible to \tcode{bool} & + \tcode{decltype(a > b)} models \exposconceptx{boolean-test\-able}{boolean-testable} & \tcode{b < a} & \tcode{>} is a total ordering relation opposite to \tcode{<}. \\ \rowsep \tcode{a >= b} & - contextually - convertible to \tcode{bool} & + \tcode{decltype(a >= b)} models \exposconceptx{boolean-test\-able}{boolean-testable} & \tcode{!(a < b)} & \\ \rowsep \tcode{a <= b} & - contextually - convertible to \tcode{bool}. & + \tcode{decltype(a <= b)} models \exposconceptx{boolean-test\-able}{boolean-testable} & \tcode{!(a > b)} & \\ \end{libreqtab4b} diff --git a/source/lib-intro.tex b/source/lib-intro.tex index fe27b8126a..e250446322 100644 --- a/source/lib-intro.tex +++ b/source/lib-intro.tex @@ -1622,7 +1622,7 @@ \topline \hdstyle{Expression} & \hdstyle{Return type} & \rhdr{Requirement} \\ \capsep \tcode{a == b} & -convertible to \tcode{bool} & +\tcode{decltype(a == b)} models \exposconceptx{boolean-testa\-ble}{boolean-testable} & \tcode{==} is an equivalence relation, that is, it has the following properties: \begin{itemize} @@ -1640,7 +1640,7 @@ \topline \hdstyle{Expression} & \hdstyle{Return type} & \hdstyle{Requirement} \\ \capsep \tcode{a < b} & -convertible to \tcode{bool} & +\tcode{decltype(a < b)} models \exposconceptx{boolean-testa\-ble}{boolean-testable} & \tcode{<} is a strict weak ordering relation\iref{alg.sorting} \\ \end{oldconcepttable} @@ -1863,7 +1863,7 @@ a value of type (possibly \keyword{const}) \tcode{std::nullptr_t}. \begin{oldconcepttable}{NullablePointer}{}{cpp17.nullablepointer} -{lll} +{lx{2in}l} \topline \lhdr{Expression} & \chdr{Return type} & \rhdr{Operational semantics} \\ \capsep \tcode{P u(np);}\br & @@ -1882,17 +1882,17 @@ \ensures \tcode{t == nullptr} \\ \rowsep \tcode{a != b} & - contextually convertible to \tcode{bool} & + \tcode{decltype(a != b)} models \exposconcept{boolean-testable} & \tcode{!(a == b)} \\ \rowsep \tcode{a == np} & - contextually convertible to \tcode{bool} & + \tcode{decltype(a == np)} and \tcode{decltype(np == a)} each model \exposconcept{boolean-testable} & \tcode{a == P()} \\ \tcode{np == a} & & \\ \rowsep \tcode{a != np} & - contextually convertible to \tcode{bool} & + \tcode{decltype(a != np)} and \tcode{decltype(np != a)} each model \exposconcept{boolean-testable} & \tcode{!(a == np)} \\ \tcode{np != a} & & diff --git a/source/support.tex b/source/support.tex index fc5381ec0e..4819bad9d8 100644 --- a/source/support.tex +++ b/source/support.tex @@ -5047,7 +5047,9 @@ Otherwise, \tcode{strong_order(E, F)} if it is a well-formed expression. \item Otherwise, if the expressions \tcode{E == F} and \tcode{E < F} - are both well-formed and convertible to \tcode{bool}, + are both well-formed and + each of \tcode{decltype(E == F)} and \tcode{decltype(E < F)} models + \exposconcept{boolean-testable}, \begin{codeblock} E == F ? strong_ordering::equal : E < F ? strong_ordering::less : @@ -5079,7 +5081,9 @@ Otherwise, \tcode{weak_order(E, F)} if it is a well-formed expression. \item Otherwise, if the expressions \tcode{E == F} and \tcode{E < F} - are both well-formed and convertible to \tcode{bool}, + are both well-formed and + each of \tcode{decltype(E == F)} and \tcode{decltype(E < F)} models + \exposconcept{boolean-testable}, \begin{codeblock} E == F ? weak_ordering::equivalent : E < F ? weak_ordering::less : @@ -5112,7 +5116,9 @@ \item Otherwise, if the expressions \tcode{E == F}, \tcode{E < F}, and \tcode{F < E} - are all well-formed and convertible to \tcode{bool}, + are all well-formed and + each of \tcode{decltype(E == F)} and \tcode{decltype(E < F)} models + \exposconcept{boolean-testable}, \begin{codeblock} E == F ? partial_ordering::equivalent : E < F ? partial_ordering::less : diff --git a/source/threads.tex b/source/threads.tex index 8e15c4c629..4f70a9a949 100644 --- a/source/threads.tex +++ b/source/threads.tex @@ -30,8 +30,14 @@ \pnum Throughout this Clause, the names of template parameters are used to express type requirements. -If a template parameter is named \tcode{Predicate}, \tcode{operator()} applied to -the template argument shall return a value that is convertible to \tcode{bool}. +\tcode{Predicate} is a function object type\iref{function.objects}. +Let \tcode{pred} denote an lvalue of type \tcode{Predicate}. +Then the expression \tcode{pred()} shall be well-formed and +the type \tcode{decltype(pred())} shall model +\exposconcept{boolean-testable}\iref{concept.booleantestable}. +The return value of \tcode{pred()}, converted to \tcode{bool}, +yields \tcode{true} if the corresponding test condition is satisfied, and +\tcode{false} otherwise. If a template parameter is named \tcode{Clock}, the corresponding template argument shall be a type \tcode{C} that meets the \oldconcept{Clock} requirements\iref{time.clock.req}; diff --git a/source/utilities.tex b/source/utilities.tex index 6cc9b64480..a7decf27db 100644 --- a/source/utilities.tex +++ b/source/utilities.tex @@ -1269,6 +1269,11 @@ \end{itemdecl} \begin{itemdescr} +\pnum +\expects +Each of \tcode{decltype(x.first == y.first)} and +\tcode{decltype(x.second == y.second)} models \exposconcept{boolean-testable}. + \pnum \returns \tcode{x.first == y.first \&\& x.second == y.second}. @@ -2907,11 +2912,15 @@ \mandates For all \tcode{i}, where $0 \leq \tcode{i} < \tcode{sizeof...(TTypes)}$, -\tcode{get(t) == get(u)} is a valid expression -returning a type that is convertible to \tcode{bool}. +\tcode{get(t) == get(u)} is a valid expression. \tcode{sizeof...(TTypes)} equals \tcode{tuple_size_v}. +\pnum +\expects +For all \tcode{i}, \tcode{decltype(get(t) == get(u))} models +\exposconcept{boolean-testable}. + \pnum \returns \tcode{true} if \tcode{get(t) == get(u)} for all