Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/named req"

From cppreference.com
< cpp
(Added std concepts)
(Undo revision 142658 by Alex DeWHu (talk). Better to let the pages link to the concepts, the concepts don't exactly align with the named requirements (especially std::copyable))
Line 4: Line 4:
 
The ''named requirements'' listed on this page are the named requirements used in the normative text of the C++ standard to define the expectations of the standard library.
 
The ''named requirements'' listed on this page are the named requirements used in the normative text of the C++ standard to define the expectations of the standard library.
  
Some of these requirements are formalized in C++20 using the [[cpp/language/constraints|concepts]] language feature. For the rest, the burden is on the programmer to ensure that library templates are instantiated with template arguments that satisfy these requirements. Failure to do so <del>may</del> will result in very complex compiler diagnostics.
+
Some of these requirements are being formalized in C++20 using the [[cpp/language/constraints|concepts]] language feature. Until then, the burden is on the programmer to ensure that library templates are instantiated with template arguments that satisfy these requirements. Failure to do so may result in very complex compiler diagnostics.
  
 
{{dsc begin}}
 
{{dsc begin}}
 
{{dsc h1|Basic}}
 
{{dsc h1|Basic}}
 
+
{{dsc named req|cpp/named req/DefaultConstructible|specifies that an object of the type can be default constructed}}
{{dsc named req|cpp/named req/Destructible|specifies that an object of the type can be destroyed|
+
{{dsc named req|cpp/named req/MoveConstructible|specifies that an object of the type can be constructed from rvalue|notes={{mark c++11}}}}
notes=<br>{{small|{{ltt|cpp/concepts/destructible|std::destructible}}{{mark c++20}}}}}}
+
{{dsc named req|cpp/named req/CopyConstructible|specifies that an object of the type can be constructed from lvalue}}
 
+
{{dsc named req|cpp/named req/MoveAssignable|specifies that an object of the type can be assigned from rvalue|notes={{mark c++11}}}}
{{dsc named req|cpp/named req/DefaultConstructible|
+
{{dsc named req|cpp/named req/CopyAssignable|specifies that an object of the type can be assigned from lvalue}}
specifies that an object of the type can be default constructed|notes=<br>
+
{{dsc named req|cpp/named req/Destructible|specifies that an object of the type can be destroyed}}
{{small|{{ltt|cpp/concepts/default_initializable|std::default_initializable}}{{mark c++20}}}}}}
+
 
+
{{dsc named req|cpp/named req/MoveConstructible|
+
specifies that an object of the type can be constructed from rvalue|notes={{mark c++11}}<br>
+
{{small|{{ltt|cpp/concepts/move_constructible|std::move_constructible}}{{mark c++20}}}}}}
+
 
+
{{dsc named req|cpp/named req/CopyConstructible|
+
specifies that an object of the type can be constructed from lvalue|notes=<br>
+
{{small|{{ltt|cpp/concepts/copy_constructible|std::copy_constructible}}{{mark c++20}}}}}}
+
 
+
{{dsc named req|cpp/named req/MoveAssignable|
+
specifies that an object of the type can be assigned from rvalue|notes={{mark c++11}}<br>
+
{{small|{{ltt|cpp/concepts/movable|std::movable}}{{mark c++20}}}}}}
+
 
+
{{dsc named req|cpp/named req/CopyAssignable|
+
specifies that an object of the type can be assigned from lvalue|notes=<br>
+
{{small|{{ltt|cpp/concepts/copyable|std::copyable}}{{mark c++20}}}}}}
+
  
 
{{dsc h1|Type properties}}
 
{{dsc h1|Type properties}}
Line 42: Line 25:
  
 
{{dsc h1|Library-wide}}
 
{{dsc h1|Library-wide}}
 
+
{{dsc named req|cpp/named req/EqualityComparable|{{tt|operator{{==}}}} is an equivalence relation}}
{{dsc named req|cpp/named req/EqualityComparable|
+
{{tt|operator{{==}}}} is an equivalence relation|notes=<br>
+
{{small|{{ltt|cpp/concepts/equality_comparable|std::equality_comparable}}{{mark c++20}}}}}}
+
 
+
 
{{dsc named req|cpp/named req/LessThanComparable|{{tt|operator<}} is a strict weak ordering relation}}
 
{{dsc named req|cpp/named req/LessThanComparable|{{tt|operator<}} is a strict weak ordering relation}}
 
+
{{dsc named req|cpp/named req/Swappable|can be swapped with an unqualified non-member function call {{c|swap()}}|notes={{mark c++11}}}}
{{dsc named req|cpp/named req/Swappable|
+
can be swapped with an unqualified non-member function call {{c|swap()}}|notes={{mark c++11}}<br>
+
{{small|{{ltt|cpp/concepts/swappable|std::swappable}}{{mark c++20}}}}}}
+
 
+
 
{{dsc named req|cpp/named req/ValueSwappable|an {{named req|Iterator}} that dereferences to a {{named req|Swappable}} type|notes={{mark c++11}}}}
 
{{dsc named req|cpp/named req/ValueSwappable|an {{named req|Iterator}} that dereferences to a {{named req|Swappable}} type|notes={{mark c++11}}}}
 
 
{{dsc named req|cpp/named req/NullablePointer|a pointer-like type supporting a null value|notes={{mark c++11}}}}
 
{{dsc named req|cpp/named req/NullablePointer|a pointer-like type supporting a null value|notes={{mark c++11}}}}
 
{{dsc named req|cpp/named req/Hash|a {{named req|FunctionObject}} that for inputs with different values has a low probability of giving the same output|notes={{mark c++11}}}}
 
{{dsc named req|cpp/named req/Hash|a {{named req|FunctionObject}} that for inputs with different values has a low probability of giving the same output|notes={{mark c++11}}}}
Line 60: Line 34:
 
{{dsc named req|cpp/named req/FunctionObject|an object that can be called with the function call syntax}}
 
{{dsc named req|cpp/named req/FunctionObject|an object that can be called with the function call syntax}}
 
{{dsc named req|cpp/named req/Callable|a type for which the invoke operation is defined}}
 
{{dsc named req|cpp/named req/Callable|a type for which the invoke operation is defined}}
 
+
{{dsc named req|cpp/named req/Predicate|a {{named req|FunctionObject}} that returns a value convertible to {{c|bool}} for one argument without modifying it}}
{{dsc named req|cpp/named req/Predicate|a {{named req|FunctionObject}} that returns a value convertible to {{c|bool}} for one argument without modifying it|notes=<br>
+
{{small|{{ltt|cpp/concepts/predicate|std::predicate}}{{mark c++20}}}}}}
+
 
+
 
{{dsc named req|cpp/named req/BinaryPredicate|a {{named req|FunctionObject}} that returns a value convertible to {{c|bool}} for two arguments without modifying them}}
 
{{dsc named req|cpp/named req/BinaryPredicate|a {{named req|FunctionObject}} that returns a value convertible to {{c|bool}} for two arguments without modifying them}}
 
{{dsc named req|cpp/named req/Compare|a {{named req|BinaryPredicate}} that establishes an ordering relation}}
 
{{dsc named req|cpp/named req/Compare|a {{named req|BinaryPredicate}} that establishes an ordering relation}}
Line 136: Line 107:
  
  
===See also===
+
{{todo|Any other missing requirement?}}
{{lt|cpp/concepts}}
+
 
+
  
 
{{langlinks|ar|de|es|fr|it|ja|pt|ru|zh}}
 
{{langlinks|ar|de|es|fr|it|ja|pt|ru|zh}}

Revision as of 01:50, 1 September 2022

 
 
C++ named requirements
 

The named requirements listed on this page are the named requirements used in the normative text of the C++ standard to define the expectations of the standard library.

Some of these requirements are being formalized in C++20 using the concepts language feature. Until then, the burden is on the programmer to ensure that library templates are instantiated with template arguments that satisfy these requirements. Failure to do so may result in very complex compiler diagnostics.

Contents

Basic

specifies that an object of the type can be default constructed
(named requirement)
specifies that an object of the type can be constructed from rvalue
(named requirement)
specifies that an object of the type can be constructed from lvalue
(named requirement)
specifies that an object of the type can be assigned from rvalue
(named requirement)
specifies that an object of the type can be assigned from lvalue
(named requirement)
specifies that an object of the type can be destroyed
(named requirement)

Type properties

Note: the standard does not define named requirements with names specified in this subcategory.
These are type categories defined by the core language. They are included here as named requirements only for consistency.
object types that are not array types or class types
(named requirement)
POD (Plain Old Data) types, compatible with C struct
(named requirement)
objects of these types can maintain their values after copying their underlying bytes
(named requirement)
objects of these types can be trivially constructed and copied
(named requirement)
these types are useful for communicating with code written in other programming languages
(named requirement)
objects of these types can be implicitly created, and their lifetimes can be implictly started
(named requirement)

Library-wide

operator== is an equivalence relation
(named requirement)
operator< is a strict weak ordering relation
(named requirement)
(C++11)
can be swapped with an unqualified non-member function call swap()
(named requirement)
an LegacyIterator that dereferences to a Swappable type
(named requirement)
a pointer-like type supporting a null value
(named requirement)
(C++11)
a FunctionObject that for inputs with different values has a low probability of giving the same output
(named requirement)
a class type that contains allocation information
(named requirement)
an object that can be called with the function call syntax
(named requirement)
a type for which the invoke operation is defined
(named requirement)
a FunctionObject that returns a value convertible to bool for one argument without modifying it
(named requirement)
a FunctionObject that returns a value convertible to bool for two arguments without modifying them
(named requirement)
a BinaryPredicate that establishes an ordering relation
(named requirement)

Container

data structure that allows element access using iterators
(named requirement)
container using bidirectional iterators
(named requirement)
container using an allocator
(named requirement)
container with elements stored linearly
(named requirement)
container with elements stored at adjacent memory addresses
(named requirement)
container that stores elements by associating them to keys
(named requirement)
container that stores elements stored in buckets by associating them to keys
(named requirement)
Container element
element can be default-constructed in uninitialized storage
(named requirement)
element can be copy-constructed in uninitialized storage
(named requirement)
element can be move-constructed in uninitialized storage
(named requirement)
element can be constructed in uninitialized storage
(named requirement)
(C++11)
element can be destroyed using an allocator
(named requirement)

Iterator

general concept to access data within some data structure
(named requirement)
iterator that can be used to read data
(named requirement)
iterator that can be used to write data
(named requirement)
iterator that can be used to read data multiple times
(named requirement)
iterator that can be both incremented and decremented
(named requirement)
iterator that can be advanced in constant time
(named requirement)
iterator to contiguously-allocated elements
(named requirement)
iterator that can be used during constant expression evaluation
(named requirement)

Stream I/O functions

a stream input function that does not skip leading whitespace and counts the processed characters
(named requirement)
a stream input function that skips leading whitespace
(named requirement)
a basic stream output function
(named requirement)
a stream output function that sets failbit on errors and returns a reference to the stream
(named requirement)

Random Number Generation

consumes a sequence of integers and produces a sequence of 32-bit unsigned values
(named requirement)
returns uniformly distributed random unsigned integers
(named requirement)
a deterministic UniformRandomBitGenerator, defined by the seed
(named requirement)
a RandomNumberEngine that transforms the output of another RandomNumberEngine
(named requirement)
returns random numbers distributed according to a given mathematical probability density function
(named requirement)

Concurrency

provides exclusive ownership semantics for execution agents (i.e. threads)
(named requirement)
(C++11)
a BasicLockable that supports attempted lock acquisition
(named requirement)
a Lockable that supports timed lock acquisition
(named requirement)
provides shared ownership semantics for execution agents (i.e. threads)
(named requirement)
a SharedLockable that supports timed lock acquisition
(named requirement)
(C++11)
a Lockable that protects against data races and sequentially consistent synchronization
(named requirement)
(C++11)
a TimedLockable that protects against data races and sequentially consistent synchronization
(named requirement)
a Mutex that supports shared ownership semantics
(named requirement)
a TimedMutex that supports shared ownership semantics
(named requirement)

Other

describes a property of a type
(named requirement)
describes a relationship between two types
(named requirement)
modifies a property of a type
(named requirement)
(C++11)
aggregates a duration, a time point, and a function to get the current time point
(named requirement)
a Clock that does not throw exceptions
(named requirement)
defines types and functions for a character type
(named requirement)
bitset, integer, or enumeration
(named requirement)
a type for which initialization is effectively equal to assignment
(named requirement)
defines types and functions used by the regular expressions library
(named requirement)
(C++11)(deprecated in C++20)
a type with constexpr constructor
(named requirement)
(C++20)
defines functions used by the formatting library
(named requirement)