Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/content/docs/cpp/language/named_req/_meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
label: Name Requirements
59 changes: 59 additions & 0 deletions src/content/docs/cpp/language/named_req/copy-asssignable.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: "C++ named requirements: CopyAssignable"
cppdoc:
revision:
since: C++11
---

import { DR, DRList } from "@components/defect-report";
import { Desc, DescList } from "@components/desc-list";
import Missing from "@components/Missing.astro";
import { Revision, RevisionBlock } from "@components/revision";

Specifies that an instance of the type can be copy-assigned from an lvalue expression.


## Requirements

The type T satisfies _CopyAssignable_ if

- The type T satisfies _MoveAssignable_, and

Given

- `t`, a modifiable lvalue expression of type `T`,
- `v`, an lvalue expression of type `T` or `const T` or an rvalue expression of type `const T`.

The following expressions must be valid and have their specified effects.

|Expression| Return type | Return value |Post-conditions|
|---|---|---|---|
|`t=v`| `T&` | `t` |The value of t is equivalent to the value of v.<br/> The value of v is unchanged. |

## See also

<DescList>
<Desc kind="class template">
<Fragment slot="item">
<RevisionBlock noborder since="C++11">
<Missing> `std::is_copy_assignable` </Missing>
</RevisionBlock>
<RevisionBlock noborder since="C++11">
<Missing> `std::is_trivially_copy_assignable` </Missing>
</RevisionBlock>
<RevisionBlock noborder since="C++11">
<Missing> `std::is_nothrow_copy_assignable` </Missing>
</RevisionBlock>
</Fragment>
checks if a type has a copy assignment operator
</Desc>
<Desc kind="concept">
<Fragment slot="item">
<RevisionBlock noborder since="C++20">
<Missing> `assignable_from` </Missing>
</RevisionBlock>
</Fragment>
specifies that an object of a type can be default constructed
</Desc>
</DescList>

93 changes: 93 additions & 0 deletions src/content/docs/cpp/language/named_req/default-constructible.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
title: "C++ named requirements: DefaultConstructible"
cppdoc:
revision:
since: C++11
---

import { DR, DRList } from "@components/defect-report";
import { Desc, DescList } from "@components/desc-list";
import Missing from "@components/Missing.astro";
import { Revision, RevisionBlock } from "@components/revision";

Specifies that an instance of the type can be default constructed.


## Requirements
The type `T` satisfies _DefaultConstructible_ if all following statements and expressions are valid and have their specified effects:

Given

- `u`, an expression of type `T`.

- `u`, an lvalue expression of type `Key`.

|Expression/Statement| Postcondition|
|---|---|
|`T u;`| The object `u` is default-initialized.|
|`T u{};`| The object `u` is value-initialized or aggregate-initialized.|
|`T()`| All resources owned by `u` are reclaimed, no exceptions are thrown.|
|`T{}`| A temporary object of type `T` is value-initialized or aggregate-initialized.|

## Notes

For objects of non-aggregate class type, a public default constructor must be defined (either user-defined or implicitly defined) to satisfy _DefaultConstructible_.

Non-const objects of non-class object type are always _DefaultConstructible_.

Const non-class types are not _DefaultConstructible_.

Const aggregate types are not _DefaultConstructible_ if any of their members is an object of non-class type.

Non-object types (function types, reference types, and the (possibly cv-qualified) type void) as well as the const non-object types are never _DefaultConstructible_.

# Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

<DRList>
<DR kind="lwg" id={724} std="C++98">
<Fragment slot="behavior-published">
the requirements of _DefaultConstructible_ were missing
</Fragment>
<Fragment slot="correct-behavior">
added
</Fragment>
</DR>
<DR kind="lwg" id={2170} std="C++98">
<Fragment slot="behavior-published">
initialzing an object of a _DefaultConstructible_ type with an
empty initializer could only result in value-initialization
</Fragment>
<Fragment slot="correct-behavior">
can also lead to aggregate-initialization
</Fragment>
</DR>
</DRList>
## See also

<DescList>
<Desc kind="class template">
<Fragment slot="item">
<RevisionBlock noborder since="C++11">
<Missing> `std::is_default_constructible` </Missing>
</RevisionBlock>
<RevisionBlock noborder since="C++11">
<Missing> `std::is_trivially_default_constructible` </Missing>
</RevisionBlock>
<RevisionBlock noborder since="C++11">
<Missing> `std::is_nothrow_default_constructible` </Missing>
</RevisionBlock>
</Fragment>
checks if a type has a default constructor
</Desc>
<Desc kind="concept">
<Fragment slot="item">
<RevisionBlock noborder since="C++20">
<Missing> `default_initializable` </Missing>
</RevisionBlock>
</Fragment>
specifies that an object of a type can be default constructed
</Desc>
</DescList>

62 changes: 62 additions & 0 deletions src/content/docs/cpp/language/named_req/destructible.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: "C++ named requirements: Destructible"
cppdoc:
revision:
since: C++11
---

import { DR, DRList } from "@components/defect-report";
import { Desc, DescList } from "@components/desc-list";
import Missing from "@components/Missing.astro";
import { Revision, RevisionBlock } from "@components/revision";

Specifies that an instance of the type can be destructed.


## Requirements
The type `T` satisfies `Destructible` if

Given

- `u`, an expression of type `T`.

- `u`, an lvalue expression of type `Key`.

|Expression| Post-Conditions|
|---|---|
|`u.~T()`| All resources owned by `u` are reclaimed, no exceptions are thrown.|

## Notes


Destructors are called implicitly at the end of object lifetime such as when leaving scope or by the delete-expression. Explicit destructor call as shown in the type requirement table is rare.

Thanks to pseudo destructor call, all scalar types meet the requirement of Destructible, while array types and reference types do not. Note that `std::is_destructible` allows arrays and reference types.

## See also

<DescList>
<Desc kind="class template">
<Fragment slot="item">
<RevisionBlock noborder since="C++11">
<Missing> `std::is_destructible` </Missing>
</RevisionBlock>
<RevisionBlock noborder since="C++11">
<Missing> `std::is_trivially_destructible` </Missing>
</RevisionBlock>
<RevisionBlock noborder since="C++11">
<Missing> `std::is_nothrow_destructible` </Missing>
</RevisionBlock>
</Fragment>
checks if a type has a non-deleted destructor
</Desc>
<Desc kind="concept">
<Fragment slot="item">
<RevisionBlock noborder since="C++20">
<Missing> `destructible` </Missing>
</RevisionBlock>
</Fragment>
specifies that an object of the type can be destroyed
</Desc>
</DescList>

60 changes: 60 additions & 0 deletions src/content/docs/cpp/language/named_req/hash.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
title: "C++ named requirements: Hash"
cppdoc:
revision:
since: C++11
---

import { DR, DRList } from "@components/defect-report";
import { Desc, DescList } from "@components/desc-list";
import DocLink from "@components/DocLink.astro"
import { Revision, RevisionBlock } from "@components/revision";

A ***Hash*** is a function object for which the output depends only on the input and has a very low probability of yielding the same output given different input values.


## Requirements
The type `T` satisfies `Hash` if

The type `T` satisfies `FunctionObject`, `CopyConstructible`, `Destructible`, and
Given

- `h`, a value of type `T` or const `T`, whose argument type is `Key`,
- `k`, a value of type convertible to `Key` or `const Key`,
- `u`, an lvalue expression of type `Key`.

The following expressions must be valid and have their specified effects.

|Expression| Return type| Requirements|
|---|---|---|
|`h(k)`| `std::size_t`|The returned value depends only on the value of `k` for the duration of the program. <br/> All evaluations of `h(k)` executed within a given execution of a program yield the same result for the same value of `k`.<br/> The probability of `h(a) == h(b)` for `a != b` should approach `1.0 / std::numeric_limits<std::size_t>::max()`.|
|`h(u)` | `std::size_t` | `u` is not modified.|

## Standard Library

<DescList>
<Desc kind="class template">
<Fragment slot="item">
<RevisionBlock noborder since="C++11" vertical>
<DocLink dest="/cpp/library/utility/hash"> `hash` </DocLink>
</RevisionBlock>
</Fragment>
hash function object
</Desc>
</DescList>

# Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

<DRList>
<DR kind="lwg" id={2291} std="C++11">
<Fragment slot="behavior-published">
same results for same arguments were required in all cases
</Fragment>
<Fragment slot="correct-behavior">
only required within a single execution
</Fragment>
</DR>
</DRList>

Loading