(C++) operator<=
January 11, 2018 · View on GitHub
(C++) operator<=
operator<= is the operator to determine if the left-hand instance is less or equal the right-hand instance.
The following code uses operator<= to determine that one plus two is less or equal equal to three:
#include <iostream> int main() { if (1 + 2 <= 3) std::cout << "One plus two is less or equal than three" << std::endl; }
operator<= is encapsulated by the functor std::less_equal.
Advice
- Reversing the order of the pair of symbols in the operators !=, >= and <= (by writing them as =!, => and =< respectively) is normally a syntax error [1]
References
- Paul Deitel, Harvey Deitel. C++11 for programmers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 2.4, Common Programming Error 2.2. page 32: 'Reversing the order of the pair of symbols in the operators !=, >= and < (by writing them as =!, => and =< respectively) is normally a syntax error. In some cases, writing != as =! will not be a syntax error, but almost certainly will be a logic error that has an effect at execution time.'