Name

rel_ops namespace — Relational operators

Synopsis

namespace std {
 namespace rel_ops {
  template<typename T> bool operator!=(const T&, const T&);
  template<typename T> bool operator> (const T&, const T&);
  template<typename T> bool operator<=(const T&, const T&);
  template<typename T> bool operator>=(const T&, const T&);
 }
}

The std::rel_ops namespace declares four comparison operators. The four operators are implemented in terms of the == and < operators. The rel_ops namespace has limited utility. If you are using an unusual class, which has only operator== and operator<, you can add a using namespace std::rel_ops directive to a function that makes heavy use of comparison operators and this unusual class. Even better, though, is fixing the class declaration to provide all necessary comparison operators. If you are writing a class that represents an ordered value, you should provide all six operators and not force your users to rely on rel_ops. The Boost project has templates that you can derive from to fill in all the relational operators, based on equality and less-than. See Appendix B for information about Boost.

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.