Template talk:par pred1
void* pred(Type &a); Works too (on a non-const range);
void* pred(convertibe b); as well.
The predicate-requirements are far too stringently formulated.
94.220.161.15 17:53, 15 November 2014 (PST)
- Actually Predicate cannot be a function, because it must be a function object, such as a pointer-to-function! Agree that the wording needs to be improved. --D41D8CD98F (talk) 04:20, 23 November 2014 (PST)
Typo in "nor is Type1 unless for Type1 a move is equivalent to a copy"
This should most likely read "(thus, Type1 & is not allowed, nor is Type1&& unless for Type1 a move is equivalent to a copy (since C++11))."
if the intent is to limit modification of v (although I need to check the standardese if that intent is correct since as other posters mention, the compiler(s) accept predicates which take T&) relevant standardese, 25.2 par8:
When not otherwise constrained, 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 argu�ments with respective value types T1 and T2, it should work correctly in the construct binary_pred(*first1,
- first2) contextually converted to bool (7.3). Unless otherwise specified, BinaryPredicate always takes
the first iterator’s value_type as its first argument, that is, in those cases when T value is part of the signature, it should work correctly in the construct binary_pred(*first1, value) contextually converted to bool (7.3). binary_pred shall not apply any non-constant function through the dereferenced iterators. Given a glvalue u of type (possibly const) T1 that designates the same object as *first1, and a glvalue v of type (possibly const) T2 that designates the same object as *first2, binary_pred(u, *first2), binary_pred(*first1, v), and binary_pred(u, v) shall each be a valid expression that is equal to binary_pred(*first1, *first2), and binary_pred(u, value) shall be a valid expression that is equal to binary_pred(*first1, value).
Thus, a parameter type of or a parameter of type?
Shouldn't this be a parameter of type ...?
- grammatically, i'd just drop 'of'; "parameter type VT& is not allowed". Except of course as the previous comments in this Talk page say, it may not be technically correct in its attempt to summarize https://eel.is/c++draft/algorithms.requirements#6 and https://eel.is/c++draft/algorithms.requirements#7. --Cubbi (talk) 14:15, 15 October 2022 (PDT)
To super Admin. Please update this template. Code is provided.
Presently, this template erroneously adds (since C++11) revision mark to an internal sub-note even on client pages of C++11++ components, such as:
erase_iffor containers, mostly (C++20).- std::forward_list, std::inplace_vector, std::hive
- some "C++11 and later" algorithms.
Which is obviously incorrect, e.g.:
Parameters
| pred | - | unary predicate which returns true if the element should be erased. The expression |
Expected presentation, for, e.g. erase_if(forward_list&, pred):
| pred | - | unary predicate which returns true if the element should be erased.The expression |
The following code is an updated version of this protected {{par_pred1}} template which adds c++98=yes/no(optional) parameter and fixes the issue:
{{par|{{{1|}}}|unary predicate {{#if:{{{2|}}}|which returns {{c|{{{value|true}}}}} {{{2}}}}}.<br/><!--
-->{{#vardefine:cpp11note|, nor is {{c|{{#if:{{{p1|}}}|VT|{{{t1}}}}}}} unless for {{tt|{{#if:{{{p1|}}}|VT|{{{t1}}}}}}} a move is equivalent to a copy}}
The expression {{c|{{trim|{{{1}}}}}(v)}} must be convertible to {{c|bool}} for every argument {{tt|v}} of type (possibly const) {{#if:{{{p1|}}}|{{tt|VT}}, where {{tt|VT}} is the value type of {{tt|{{{p1}}}}}|{{tt|{{{t1}}}}}}}, regardless of [[cpp/language/value_category|value category]], and must not modify {{tt|v}}. Thus, a parameter type of {{c|{{#if:{{{p1|}}}|VT|{{{t1}}}}}&}}is not allowed{{#ifeq:{{{c++98|no}}}|yes|{{rev inl|since=c++11|{{#var:cpp11note}}}}|{{#var:cpp11note}}}}.}}<noinclude>{{documentation|Template:par/doc}}</noinclude>
So, please replace the content. I'll update some pre-C++11 pages later on.
Space Mission (talk) 12:41, 16 June 2026 (UTC)