Skip to content

Commit bfd8726

Browse files
authored
Feature: util hash (#92)
* feat(): page: util hash * feat(std::hash): page for `operator()` * fix(std::hash): use doclink * feat(named_req) Hashable, DefaultConstructible, Destructible * feat(hash): update link * feat(named_req): Swappable, CopyAssignable * feat(hash): update links * fix(named_req): nix, and remove prefix "Named Requirements"
1 parent 4091ec0 commit bfd8726

File tree

8 files changed

+792
-0
lines changed

8 files changed

+792
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
label: Named Requirements
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
title: "CopyAssignable"
3+
cppdoc:
4+
revision:
5+
since: C++11
6+
---
7+
8+
import { DR, DRList } from "@components/defect-report";
9+
import { Desc, DescList } from "@components/desc-list";
10+
import Missing from "@components/Missing.astro";
11+
import { Revision, RevisionBlock } from "@components/revision";
12+
13+
Specifies that an instance of the type can be copy-assigned from an lvalue expression.
14+
15+
16+
## Requirements
17+
18+
The type T satisfies _CopyAssignable_ if
19+
20+
- The type T satisfies _MoveAssignable_, and
21+
22+
Given
23+
24+
- `t`, a modifiable lvalue expression of type `T`,
25+
- `v`, an lvalue expression of type `T` or `const T` or an rvalue expression of type `const T`.
26+
27+
The following expressions must be valid and have their specified effects.
28+
29+
|Expression| Return type | Return value |Post-conditions|
30+
|---|---|---|---|
31+
|`t=v`| `T&` | `t` |The value of t is equivalent to the value of v.<br/> The value of v is unchanged. |
32+
33+
## See also
34+
35+
<DescList>
36+
<Desc kind="class template">
37+
<Fragment slot="item">
38+
<RevisionBlock noborder since="C++11">
39+
<Missing> `std::is_copy_assignable` </Missing>
40+
</RevisionBlock>
41+
<RevisionBlock noborder since="C++11">
42+
<Missing> `std::is_trivially_copy_assignable` </Missing>
43+
</RevisionBlock>
44+
<RevisionBlock noborder since="C++11">
45+
<Missing> `std::is_nothrow_copy_assignable` </Missing>
46+
</RevisionBlock>
47+
</Fragment>
48+
checks if a type has a copy assignment operator
49+
</Desc>
50+
<Desc kind="concept">
51+
<Fragment slot="item">
52+
<RevisionBlock noborder since="C++20">
53+
<Missing> `assignable_from` </Missing>
54+
</RevisionBlock>
55+
</Fragment>
56+
specifies that an object of a type can be default constructed
57+
</Desc>
58+
</DescList>
59+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: "DefaultConstructible"
3+
cppdoc:
4+
revision:
5+
since: C++11
6+
---
7+
8+
import { DR, DRList } from "@components/defect-report";
9+
import { Desc, DescList } from "@components/desc-list";
10+
import Missing from "@components/Missing.astro";
11+
import { Revision, RevisionBlock } from "@components/revision";
12+
13+
Specifies that an instance of the type can be default constructed.
14+
15+
16+
## Requirements
17+
The type `T` satisfies _DefaultConstructible_ if all following statements and expressions are valid and have their specified effects:
18+
19+
Given
20+
21+
- `u`, an expression of type `T`.
22+
23+
- `u`, an lvalue expression of type `Key`.
24+
25+
|Expression/Statement| Postcondition|
26+
|---|---|
27+
|`T u;`| The object `u` is default-initialized.|
28+
|`T u{};`| The object `u` is value-initialized or aggregate-initialized.|
29+
|`T()`| All resources owned by `u` are reclaimed, no exceptions are thrown.|
30+
|`T{}`| A temporary object of type `T` is value-initialized or aggregate-initialized.|
31+
32+
## Notes
33+
34+
For objects of non-aggregate class type, a public default constructor must be defined (either user-defined or implicitly defined) to satisfy _DefaultConstructible_.
35+
36+
Non-const objects of non-class object type are always _DefaultConstructible_.
37+
38+
Const non-class types are not _DefaultConstructible_.
39+
40+
Const aggregate types are not _DefaultConstructible_ if any of their members is an object of non-class type.
41+
42+
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_.
43+
44+
# Defect reports
45+
46+
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
47+
48+
<DRList>
49+
<DR kind="lwg" id={724} std="C++98">
50+
<Fragment slot="behavior-published">
51+
the requirements of _DefaultConstructible_ were missing
52+
</Fragment>
53+
<Fragment slot="correct-behavior">
54+
added
55+
</Fragment>
56+
</DR>
57+
<DR kind="lwg" id={2170} std="C++98">
58+
<Fragment slot="behavior-published">
59+
initialzing an object of a _DefaultConstructible_ type with an
60+
empty initializer could only result in value-initialization
61+
</Fragment>
62+
<Fragment slot="correct-behavior">
63+
can also lead to aggregate-initialization
64+
</Fragment>
65+
</DR>
66+
</DRList>
67+
## See also
68+
69+
<DescList>
70+
<Desc kind="class template">
71+
<Fragment slot="item">
72+
<RevisionBlock noborder since="C++11">
73+
<Missing> `std::is_default_constructible` </Missing>
74+
</RevisionBlock>
75+
<RevisionBlock noborder since="C++11">
76+
<Missing> `std::is_trivially_default_constructible` </Missing>
77+
</RevisionBlock>
78+
<RevisionBlock noborder since="C++11">
79+
<Missing> `std::is_nothrow_default_constructible` </Missing>
80+
</RevisionBlock>
81+
</Fragment>
82+
checks if a type has a default constructor
83+
</Desc>
84+
<Desc kind="concept">
85+
<Fragment slot="item">
86+
<RevisionBlock noborder since="C++20">
87+
<Missing> `default_initializable` </Missing>
88+
</RevisionBlock>
89+
</Fragment>
90+
specifies that an object of a type can be default constructed
91+
</Desc>
92+
</DescList>
93+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
title: "Destructible"
3+
cppdoc:
4+
revision:
5+
since: C++11
6+
---
7+
8+
import { DR, DRList } from "@components/defect-report";
9+
import { Desc, DescList } from "@components/desc-list";
10+
import Missing from "@components/Missing.astro";
11+
import { Revision, RevisionBlock } from "@components/revision";
12+
13+
Specifies that an instance of the type can be destructed.
14+
15+
16+
## Requirements
17+
The type `T` satisfies `Destructible` if
18+
19+
Given
20+
21+
- `u`, an expression of type `T`.
22+
23+
- `u`, an lvalue expression of type `Key`.
24+
25+
|Expression| Post-Conditions|
26+
|---|---|
27+
|`u.~T()`| All resources owned by `u` are reclaimed, no exceptions are thrown.|
28+
29+
## Notes
30+
31+
32+
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.
33+
34+
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.
35+
36+
## See also
37+
38+
<DescList>
39+
<Desc kind="class template">
40+
<Fragment slot="item">
41+
<RevisionBlock noborder since="C++11">
42+
<Missing> `std::is_destructible` </Missing>
43+
</RevisionBlock>
44+
<RevisionBlock noborder since="C++11">
45+
<Missing> `std::is_trivially_destructible` </Missing>
46+
</RevisionBlock>
47+
<RevisionBlock noborder since="C++11">
48+
<Missing> `std::is_nothrow_destructible` </Missing>
49+
</RevisionBlock>
50+
</Fragment>
51+
checks if a type has a non-deleted destructor
52+
</Desc>
53+
<Desc kind="concept">
54+
<Fragment slot="item">
55+
<RevisionBlock noborder since="C++20">
56+
<Missing> `destructible` </Missing>
57+
</RevisionBlock>
58+
</Fragment>
59+
specifies that an object of the type can be destroyed
60+
</Desc>
61+
</DescList>
62+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: "Hash"
3+
cppdoc:
4+
revision:
5+
since: C++11
6+
---
7+
8+
import { DR, DRList } from "@components/defect-report";
9+
import { Desc, DescList } from "@components/desc-list";
10+
import DocLink from "@components/DocLink.astro"
11+
import { Revision, RevisionBlock } from "@components/revision";
12+
13+
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.
14+
15+
16+
## Requirements
17+
The type `T` satisfies `Hash` if
18+
19+
The type `T` satisfies `FunctionObject`, `CopyConstructible`, `Destructible`, and
20+
Given
21+
22+
- `h`, a value of type `T` or const `T`, whose argument type is `Key`,
23+
- `k`, a value of type convertible to `Key` or `const Key`,
24+
- `u`, an lvalue expression of type `Key`.
25+
26+
The following expressions must be valid and have their specified effects.
27+
28+
|Expression| Return type| Requirements|
29+
|---|---|---|
30+
|`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()`.|
31+
|`h(u)` | `std::size_t` | `u` is not modified.|
32+
33+
## Standard Library
34+
35+
<DescList>
36+
<Desc kind="class template">
37+
<Fragment slot="item">
38+
<RevisionBlock noborder since="C++11" vertical>
39+
<DocLink dest="/cpp/library/utility/hash"> `hash` </DocLink>
40+
</RevisionBlock>
41+
</Fragment>
42+
hash function object
43+
</Desc>
44+
</DescList>
45+
46+
# Defect reports
47+
48+
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
49+
50+
<DRList>
51+
<DR kind="lwg" id={2291} std="C++11">
52+
<Fragment slot="behavior-published">
53+
same results for same arguments were required in all cases
54+
</Fragment>
55+
<Fragment slot="correct-behavior">
56+
only required within a single execution
57+
</Fragment>
58+
</DR>
59+
</DRList>
60+

0 commit comments

Comments
 (0)