boolean - return type of bool function -


what return type of sort of bool function...... know return type either true of false seems complicated when have got this..

bool mypredicate (int i, int j) { return (i==j); } 

this bool function used in library function called equal...... example is....

bool compare(int a, int b){ return a<b; } 

so perspective here return type of these bool function.when goes true & false....

your functions mypredicate , compare merely thin wrappers on binary operators == , <. operators functions: take number of arguments of given type, , return result of given type.

for example, imagine function bool operator==(int a, int b) following specification:

  • if a equals b return true
  • otherwise return false

and function bool operator<(int a, int b) following specification:

  • if a strictly lesser b return true
  • otherwise return false.

then write:

bool mypredicate (int i, int j) {     return operator==(i, j); }  bool compare(int a, int b){     return operator<(a, b); } 

for convenience, programming languages allow use shorter, functionnaly equivalent syntax: i == j , a < b.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -