Possible Duplicate:
What is predicate in C++?
When I read the C++ primer, there is a defined term which is predicate.
The definition is this :
Functions that returns a type that can be converted to bool. Often used by the generic algorithms to test elements . predicates used by the library are either unary (taking one argument) or binary(taking two).
Anyone that returns a type that can be converted to bool can be predicate ! Right? Or there are some other restrictive conditions.
Thanks!
There’s no formal definition of a predicate in the context of C++ (that I know of anyway), but it generally means a function that can be used in a true/false context.
Here’s a possible implementation of count_if from cppreference that illustrates what it’s talking about:
pmust return something that can be used inside of anifstatement is what it basically boils down to.For example:
This is not a valid predicate for count_if because T is not implicitly convertible to a bool.
In other words:
Is uncompilable code.
If, however, T could be implicitly converted to a bool,
fwould be an acceptable predicate (though very odd).