Skip to content

Commit 35e9b89

Browse files
committed
feat(named_req) Hashable, DefaultConstructible, Destructible
1 parent 74fd43c commit 35e9b89

File tree

4 files changed

+210
-0
lines changed

4 files changed

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

0 commit comments

Comments
 (0)