# Concepts library (since C++20)

From cppreference.com
< cpp

The concepts library provides definitions of fundamental library concepts that can be used to perform compile-time validation of template arguments and perform function dispatch based on properties of types. These concepts provide a foundation for equational reasoning in programs.

Most concepts in the standard library impose both syntactic and semantic requirements. It is said that a standard concept is satisfied if its syntactic requirements are met, and is modeled if it is satisfied and its semantic requirements (if any) are also met.

In general, only the syntactic requirements can be checked by the compiler. If the validity or meaning of a program depends whether a sequence of template arguments models a concept, and the concept is satisfied but not modeled, or if a semantic requirement is not met at the point of use, the program is ill-formed, no diagnostic required.

### Equality preservation

An expression is equality-preserving if it results in equal outputs given equal inputs, where

- the inputs consist of its operands (not neccessarily making the expression semantically valid), and
- the outputs consist of its result and all modifications to the operands by the expression, if any

where, for convenience of wording, its "operands" refer to its largest sub-expressions that consist of an id-expression or invocations of `std::move`, std::forward, and std::declval.

The cv-qualification and value category of each operand is determined by assuming that each template type parameter in its type denotes a cv-unqualified complete non-array object type.

Every expression required to be equality preserving is further required to be stable, that is, two evaluations of it with the same input objects must have equal outputs without any explicit intervening modification of those input objects.

Unless noted otherwise, every expression used in a requires-expression of the standard library concepts is required to be equality preserving, and the evaluation of the expression may modify only its non-constant operands. Operands that are constant must not be modified.

In the standard library, the following concepts are allowed to have non equality-preserving requires-expressions: `output_iterator`, `indirectly_writable`, `invocable` (but not `regular_invocable`), `weakly_incrementable` (but not `incrementable`), `range` (but not `forward_range`) and some others.

### Standard library concepts (since C++20)

Defined in namespace `std`
##### Core language concepts
Defined in header `<concepts>`
same_as (C++20) | specifies that a type is the same as another type (concept)
derived_from (C++20) | specifies that a type is derived from another type (concept)
convertible_to (C++20) | specifies that a type is implicitly convertible to another type (concept)
common_reference_with (C++20) | specifies that two types share a common reference type (concept)
common_with (C++20) | specifies that two types share a common type (concept)
integral (C++20) | specifies that a type is an integral type (concept)
signed_integral (C++20) | specifies that a type is an integral type that is signed (concept)
unsigned_integral (C++20) | specifies that a type is an integral type that is unsigned (concept)
floating_point (C++20) | specifies that a type is a floating-point type (concept)
assignable_from (C++20) | specifies that a type is assignable from another type (concept)
swappable swappable_with (C++20) | specifies that a type can be swapped or that two types can be swapped with each other (concept)
destructible (C++20) | specifies that an object of the type can be destroyed (concept)
constructible_from (C++20) | specifies that a variable of the type can be constructed from or bound to a set of argument types (concept)
default_initializable (C++20) | specifies that an object of a type can be default constructed (concept)
move_constructible (C++20) | specifies that an object of a type can be move constructed (concept)
copy_constructible (C++20) | specifies that an object of a type can be copy constructed and move constructed (concept)
##### Comparison concepts
Defined in header `<concepts>`
boolean-testable (C++20) | specifies that a type can be used in Boolean contexts (exposition-only concept*)
equality_comparable equality_comparable_with (C++20) | specifies that operator == is an equivalence relation (concept)
totally_ordered totally_ordered_with (C++20) | specifies that the comparison operators on the type yield a total order (concept)
Defined in header `<compare>`
three_way_comparable three_way_comparable_with (C++20) | specifies that operator <=> produces consistent result on given types (concept)
##### Object concepts
Defined in header `<concepts>`
movable (C++20) | specifies that an object of a type can be moved and swapped (concept)
copyable (C++20) | specifies that an object of a type can be copied, moved, and swapped (concept)
semiregular (C++20) | specifies that an object of a type can be copied, moved, swapped, and default constructed (concept)
regular (C++20) | specifies that a type is regular, that is, it is both `semiregular` and `equality_comparable` (concept)
##### Callable concepts
Defined in header `<concepts>`
invocable regular_invocable (C++20) | specifies that a callable type can be invoked with a given set of argument types (concept)
predicate (C++20) | specifies that a callable type is a Boolean predicate (concept)
relation (C++20) | specifies that a callable type is a binary relation (concept)
equivalence_relation (C++20) | specifies that a `relation` imposes an equivalence relation (concept)
strict_weak_order (C++20) | specifies that a `relation` imposes a strict weak ordering (concept)

Additional concepts can be found in the iterators library, the algorithms library, and the ranges library.

### See also

- Named Requirements

Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/concepts&oldid=149534"