The bit_or is an inbuilt function in C++ which is used to perform bitwise_or and return the result after applying the bitwise_or operation on it’s arguments.
template <class T> struct bit_or;
Parameters: It accepts a parameter T which is the type of the argument to be compared by the functional call.
- Objects of this class can be used on standard algorithms such as transform or accumulate.
- Member functions ( ‘operator()’ ) returns the bitwise_or of its arguments.
We must include the library ‘functional’ and ‘algorithm’ to use bit_or and transform() respectively.
Below is the illustration of bit_or in C++:
Results: -3 2 5 101 1029
Some points to Remember
- Bitwise_or of a number with zero results into the number itself.
- Bitwise_or of two same numbers is also equal to that number itself
- If the number is odd it’s bit_or with 1 will result into same number
- If the number is even it’s bit_or with 1 will always results into “number+1”
Results: 15 1103