-
Notifications
You must be signed in to change notification settings - Fork 12
Feature: util hash #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HOMODELUNA
wants to merge
7
commits into
cppdoc-cc:main
Choose a base branch
from
HOMODELUNA:feature/util-hash-2026.01.06
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+792
−0
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0915d58
feat(): page: util hash
HOMODELUNA 6f4d624
feat(std::hash): page for `operator()`
HOMODELUNA 74fd43c
fix(std::hash): use doclink
HOMODELUNA 35e9b89
feat(named_req) Hashable, DefaultConstructible, Destructible
HOMODELUNA 3d7d464
feat(hash): update link
HOMODELUNA f89163e
feat(named_req): Swappable, CopyAssignable
HOMODELUNA 1b8a92e
feat(hash): update links
HOMODELUNA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| label: Name Requirements | ||
59 changes: 59 additions & 0 deletions
59
src/content/docs/cpp/language/named_req/copy-asssignable.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||
| --- | ||||||
| title: "C++ named requirements: CopyAssignable" | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Please also apply similar modifications to other page titles in this PR. |
||||||
| 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
93
src/content/docs/cpp/language/named_req/default-constructible.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.