Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/concepts"

From cppreference.com
< cpp
(typo)
(Adds a link to the <compare> header, which contains three_way_comparable/three_way_comparable_with concepts)
Line 45: Line 45:
 
{{dsc end}}
 
{{dsc end}}
  
Additional concepts can be found in [[cpp/iterator#Algorithm_concepts_and_utilities|the iterators library]] and [[cpp/ranges#Range_concepts|the ranges library]].
+
Additional concepts can be found in [[cpp/iterator#Algorithm_concepts_and_utilities|the iterators library]], [[cpp/ranges#Range_concepts|the ranges library]], and [[cpp/header/compare#Concepts|the <compare> header]]
  
 
{{langlinks|es|ja|ru|zh}}
 
{{langlinks|es|ja|ru|zh}}

Revision as of 23:32, 26 March 2021

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 sequenced 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.

Defined in header <concepts>
Defined in namespace std

Contents

Core language concepts
(C++20)
specifies that a type is the same as another type
(concept) [edit]
specifies that a type is derived from another type
(concept) [edit]
specifies that a type is implicitly convertible to another type
(concept) [edit]
specifies that two types share a common reference type
(concept) [edit]
specifies that two types share a common type
(concept) [edit]
(C++20)
specifies that a type is an integral type
(concept) [edit]
specifies that a type is an integral type that is signed
(concept) [edit]
specifies that a type is an integral type that is unsigned
(concept) [edit]
specifies that a type is a floating-point type
(concept) [edit]
specifies that a type is assignable from another type
(concept) [edit]
specifies that a type can be swapped or that two types can be swapped with each other
(concept) [edit]
specifies that an object of the type can be destroyed
(concept) [edit]
specifies that a variable of the type can be constructed from or bound to a set of argument types
(concept) [edit]
specifies that an object of a type can be default constructed
(concept) [edit]
specifies that an object of a type can be move constructed
(concept) [edit]
specifies that an object of a type can be copy constructed and move constructed
(concept) [edit]
Comparison concepts
 (C++20)
specifies that a type can be used in Boolean contexts
(exposition-only concept*)[edit]
specifies that operator == is an equivalence relation
(concept) [edit]
specifies that the comparison operators on the type yield a total order
(concept) [edit]
Object concepts
(C++20)
specifies that an object of a type can be moved and swapped
(concept) [edit]
(C++20)
specifies that an object of a type can be copied, moved, and swapped
(concept) [edit]
specifies that an object of a type can be copied, moved, swapped, and default constructed
(concept) [edit]
(C++20)
specifies that a type is regular, that is, it is both semiregular and equality_comparable
(concept) [edit]
Callable concepts
specifies that a callable type can be invoked with a given set of argument types
(concept) [edit]
(C++20)
specifies that a callable type is a Boolean predicate
(concept) [edit]
(C++20)
specifies that a callable type is a binary relation
(concept) [edit]
specifies that a relation imposes an equivalence relation
(concept) [edit]
specifies that a relation imposes a strict weak ordering
(concept) [edit]

Additional concepts can be found in the iterators library, the ranges library, and the <compare> header