ConceptC++ Concept Web: Header

Concepts in the header <concepts>


Concept EqualityComparable

auto concept EqualityComparable<typename T, typename U = T> {
  bool operator==(T a, U b);
}

Concept EqualityComparable requires that two values be comparable with operator==.

When T and U are identical, operator== is an equivalence relation, that is, it satisfied the following properties:

  • For all a, a == a.
  • If a == b, then b == a.
  • If a == b and b == c, then a == c.

Concept LessThanComparable

auto concept LessThanComparable<typename T, typename U = T> {
  bool operator<(T, U);
};

Concept LessThanComparable requires the ability to order values via operator<.

operator< is a strict weak ordering relation.


Concept CopyConstructible

auto concept CopyConstructible<typename T> {
  T::T(T const&);
  T::~T();
};

Concept CopyConstructible requires the ability to create and destroy copies of an object.

Note that, unlike the copy construction requirements in the C++98 Standard Library, this definition of CopyConstructible does not contain requirements for the address-of operator&. These requirements are unrelated to copy construction, and their inclusion would prevent references from meeting the CopyConstructible requirements.


Concept Swappable

auto concept Swappable<typename T> {
  void swap(T& t, T& u);
};

Concept Swappable requires that two values t and u can be swapped, after which t has the value originally held by u and u has the value originally held by t.


Concept DefaultConstructible

auto concept DefaultConstructible<typename T> {
  T::T();
};
Concept DefaultConstructible requires the existence of an accessible default constructor.

Concept Assignable

auto concept Assignable<typename T, typename U = T> {
  typename result_type;
  result_type T::operator=(U const&); 
};

Concept Assignable requires the existence of a suitable assignment operator.


Concept Convertible

auto concept Convertible<typename T, typename U> {
  operator U(const T&);
};
 
template<typename T> concept_map Convertible {};
template<typename T> concept_map Convertible {};
template<typename T> concept_map Convertibleconst T&> {};

Concept Convertible requires an implicit conversion from one type to another.


Concept SameType

concept SameType<typename T, typename U> { /* unspecified */ };
template<typename T> concept_map SameType { /* unspecified */ };

Concept SameType requires that its two type parameters have precisely the same type. Note that compiler support is required to correctly implement the type-checking semantics of the SameType concept.


Concept True

concept True<bool> { };
concept_map True<true> { };

Concept True requires that its argument (a bool value that must be an integral constant expression) be true.


Concept Dereferenceable

auto concept Dereferenceable<typename T> {
  typename reference;
  reference operator*(T);
};

Concept Dereferenceable requires the existence of a dereference operator *.


Concept Integral

concept Integral<typename T>
  : DefaultConstructible, CopyConstructible,
    LessThanComparable, EqualityComparable {
  T::T(long long);
 
  T& operator++(T&);
  T operator++(T&, int);
  T& operator--(T&);
  T operator--(T&, int);
  T operator+(T);
  T operator+(T, T);
  T& operator+=(T&, T);
  T operator-(T, T);
  T& operator-=(T&, T);
  T operator*(T, T);
  T& operator*=(T&, T);
  T operator/(T, T);
  T& operator/=(T&, T);
  T operator%(T, T);
  T& operator%=(T&, T);
 
  T operator&(T, T);
  T& operator&=(T&, T);
  T operator|(T, T);
  T& operator|=(T&, T);
  T operator^(T, T);
  T& operator^=(T&, T);
 
  T operator<<(T, T);
  T& operator<<=(T&, T);
  T operator>>(T, T);
  T& operator>>=(T&, T);
 
  bool operator>(T, T);
  bool operator<=(T, T);
  bool operator>=(T, T);
  bool operator!=(T, T);
 
  requires Assignable, SameType<Assignable::result_type, T&>;
}
Concept Integral requires all of the operations available on built-in integral types.

Concept SignedIntegral

concept SignedIntegral<typename T> : Integral {
  T operator-(T);
};
 
concept_map SignedIntegral<signed char> { };
concept_map SignedIntegral<short> { };
concept_map SignedIntegral<int> { };
concept_map SignedIntegral<long> { };
concept_map SignedIntegral<long long> { };

Concept SignedIntegral requires all of the operations of built-in signed integral types. All of the built-in signed integral types are models of ths concept.


Concept UnsignedIntegral

concept UnsignedIntegral<typename T> : Integral { };
 
concept_map UnsignedIntegral<unsigned char> { };
concept_map UnsignedIntegral<unsigned short> { };
concept_map UnsignedIntegral<unsigned int> { };
concept_map UnsignedIntegral<unsigned long> { };
concept_map UnsignedIntegral<unsigned long long> { };

Concept UnsignedIntegral requires all of the operations of built-in unsigned integral types. Every built-in unsigned integral type is a model of this concept.


Concept Addable

auto concept Addable<typename T, typename U = T> {
  typename result_type;
  result_type operator+(T, U);
};
The Addable concept requires that two values can be added with the + operator.

Concept Multiplicable

auto concept Multiplicable<typename T, typename U = T> {
  typename result_type;
  result_type operator*(T, U);
};
The Multiplicable concept requires that two values can be multiplied with the * operator.

Concept CallableN

auto concept CallableN<typename F, typename T1, typename T2, ..., typename TN> {
  typename result_type;
  result_type operator()(F&, T1, T2, ..., TN);
};
The Callable family of concepts--Callable0, Callable1, ..., CallableM requires that the given parameter F be callable given arguments of types T1, T2, ..., TN.

Concept Predicate

auto concept Predicate<typename F, typename T1> : Callable1 {
  requires Convertiblebool>;
};

The Predicate concept requires that a function object be callable with a single argument, the result of which can be used in a context that requires a bool. Predicate function objects shall not apply any non-constant function through the predicate arguments.


Concept BinaryPredicate

auto concept BinaryPredicate<typename F, typename T1, typename T2> : Callable2 {
  requires Convertiblebool>;
};

The BinaryPredicate concept requires that a function object be callable with two arguments, the result of which can be used in a context that requires a bool. Predicate function objects shall not apply any non-constant function through the predicate arguments.