Your functions mypredicate
and compare
are merely thin wrappers over the binary operators ==
and <
. Operators are like functions: they take a number of arguments of a given type, and return a result of a given type.
For example, imagine a function bool operator==(int a, int b)
with the following specification:
- if
a
equalsb
then returntrue
- otherwise return
false
And a function bool operator<(int a, int b)
with the following specification:
- if
a
is strictly lesser thanb
then returntrue
- otherwise return
false
.
Then you could write:
bool mypredicate (int i, int j) {
return operator==(i, j);
}
bool compare(int a, int b){
return operator<(a, b);
}
For convenience, most programming languages allow you to use a shorter, functionnaly equivalent syntax: i == j
and a < b
.
0
solved return type of bool function