View on GitHub

Origin

Experiments in C++ Library Design

Download this project as a .zip file Download this project as a tar.gz file

Equality comparison

Synopsis

#include <origin/generic.hpp>

template<typename T>
concept bool Equality_comparable() {
  return requires (T a, T b) {
    { a == b } -> Optional;
    { a != b } -> Optional;
  };
}

Documentation

An equality comparable type can be used with == to determine when its objects are equal (i.e., have the same value), and can be used with != to determine when its objects differ.

Semantics

Example

// Assume that g is a regular function.
template<typename T>
int g(T);

template<Equality_comparable T>
void f(T a, T b)
{
  if (a == b) {
    // Because a and b are equal, we can use 
    // g(a) or g(b) and get the same results.
  }
}