Created on 2006-02-05.00:00:00 last changed 162 months ago
Proposed resolution:
Change [algorithms.general]/7+8 as indicated. [This change is recommended to bring the return value requirements of BinaryPredicate and Compare in sync.]
7 The Predicate parameter is used whenever an algorithm expects a function object that when applied to the result of dereferencing the corresponding iterator returns a value testable as true. In other words, if an algorithm takes Predicate pred as its argument and first as its iterator argument, it should work correctly in the construct
if (pred(*first)){...}pred(*first) contextually converted to bool ([conv]). The function object pred shall not apply any nonconstant function through the dereferenced iterator. This function object may be a pointer to function, or an object of a type with an appropriate function call operator.8 The BinaryPredicate parameter is used whenever an algorithm expects a function object that when applied to the result of dereferencing two corresponding iterators or to dereferencing an iterator and type T when T is part of the signature returns a value testable as true. In other words, if an algorithm takes BinaryPredicate binary_pred as its argument and first1 and first2 as its iterator arguments, it should work correctly in the construct
if (binary_pred(*first1, *first2)){...}binary_pred(*first1, *first2) contextually converted to bool ([conv]). BinaryPredicate always takes the first iterator type as its first argument, that is, in those cases when T value is part of the signature, it should work correctly in thecontext of if (binary_pred(*first1, value)){...}construct binary_pred(*first1, value) contextually converted to bool ([conv]). binary_pred shall not apply any non-constant function through the dereferenced iterators.
Change [alg.sorting]/2 as indicated:
2 Compare is
used asa function object type ([function.objects]). The return value of the function call operation applied to an object of type Compare, when contextually converted to type bool ([conv]), yields true if the first argument of the callwhich returns true if the first argumentis less than the second, and false otherwise. Compare comp is used throughout for algorithms assuming an ordering relation. It is assumed that comp will not apply any non-constant function through the dereferenced iterator.
[ 2010-01-22 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]
[ 2010-01-17: ]
Howard expresses concern that the current direction of the proposed wording outlaws expressions such as:
if (!comp(x, y))Daniel provides wording which addresses that concern.
The previous wording is saved here:
Change [alg.sorting] p2:
Compare is used as a function object. The return value of the function call operator applied to an object of type Compare, when converted to type bool, yields true if the first argument of the call
which returns true if the first argumentis less than the second, and false otherwise. Compare comp is used throughout for algorithms assuming an ordering relation. It is assumed that comp will not apply any non-constant function through the dereferenced iterator.
[ 2009-10-24 Stefanus supplied wording. ]
Move to Review once wording received. Stefanus to send proposed wording. Old proposed wording here:
I think we could fix this by rewording 25.3, p2 to read somthing like:
-2- Compare is
used as a function object which returns true if the first argumenta BinaryPredicate. The return value of the function call operator applied to an object of type Compare, when converted to type bool, yields true if the first argument of the call is less than the second, and false otherwise. Compare comp is used throughout for algorithms assuming an ordering relation. It is assumed that comp will not apply any non-constant function through the dereferenced iterator.
[ 2009-10 Santa Cruz: ]
Move to Review once wording received. Stefanus to send proposed wording.
[ 2009-10 Santa Cruz: ]
Move to Review once wording received. Stefanus to send proposed wording.
[ 2009-07-28 Reopened by Alisdair. No longer solved by concepts. ]
[ Portland: Jack to define "convertible to bool" such that short circuiting isn't destroyed. ]
In 25, p8 we allow BinaryPredicates to return a type that's convertible to bool but need not actually be bool. That allows predicates to return things like proxies and requires that implementations be careful about what kinds of expressions they use the result of the predicate in (e.g., the expression in if (!pred(a, b)) need not be well-formed since the negation operator may be inaccessible or return a type that's not convertible to bool).
Here's the text for reference:
...if an algorithm takes BinaryPredicate binary_pred as its argument and first1 and first2 as its iterator arguments, it should work correctly in the construct if (binary_pred(*first1, first2)){...}.
In 25.3, p2 we require that the Compare function object return true of false, which would seem to preclude such proxies. The relevant text is here:
Compare is used as a function object which returns true if the first argument is less than the second, and false otherwise...
History | |||
---|---|---|---|
Date | User | Action | Args |
2011-08-23 20:07:26 | admin | set | status: wp -> c++11 |
2010-10-21 18:28:33 | admin | set | messages: + msg3048 |
2010-10-21 18:28:33 | admin | set | messages: + msg3047 |
2010-10-21 18:28:33 | admin | set | messages: + msg3046 |
2010-10-21 18:28:33 | admin | set | messages: + msg3045 |
2010-10-21 18:28:33 | admin | set | messages: + msg3044 |
2010-10-21 18:28:33 | admin | set | messages: + msg3043 |
2010-10-21 18:28:33 | admin | set | messages: + msg3042 |
2010-10-21 18:28:33 | admin | set | messages: + msg3041 |
2006-02-05 00:00:00 | admin | create |