Skip to content

Commit 591a7d7

Browse files
committed
acrolinx
1 parent 9fca3a3 commit 591a7d7

2 files changed

Lines changed: 21 additions & 25 deletions

File tree

‎docs/standard-library/in-place-t-struct.md‎

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ title: "in_place_t, in_place_type_t, in_place_index_t"
44
ms.date: 11/13/2024
55
f1_keywords: ["utility/utility<in_place_t>", "utility/std::in_place_t", "utility/utility<in_place_type_t>", "utility/std::in_place_type_t", "utility<in_place_index_t>", "utility/std::in_place_index_t"]
66
helpviewer_keywords: ["utility<in_place_t> struct", "utility<in_place_type_t> struct", "utility::in_place_type_t struct", "utility<in_place_index_t> struct", "utility::in_place_index_t struct"]
7+
ai-usage: ai-assisted
78
---
89
# `in_place_t`, `in_place_type_t`, `in_place_index_t` struct
910

@@ -40,28 +41,19 @@ template <size_t I>
4041
inline constexpr in_place_index_t<I> in_place_index{};
4142
```
4243

43-
## Requirements
44-
45-
**Header:** `<utility>`
46-
47-
**Namespace:** `<utility>`
48-
49-
**Compiler Option:** [`/std:c++17`](../build/reference/std-specify-language-standard-version.md) or later.
50-
51-
5244
## Parameters
5345

54-
*I*\
55-
The index where the object will be created in place.
46+
*`I`*\
47+
The index where the object is created in place.
5648

57-
*T*\
58-
The type of object to create in place.
49+
*`T`*\
50+
The type of object to create.
5951

6052
## Remarks
6153

62-
- `in_place_t` indicates in-place construction of an object.
63-
- `in_place_type_t` indicates in-place construction of an object of a specific type.
64-
- `in_place_index_t` indicates in-place construction of an object at a specific index.
54+
- `in_place_t` indicates in-place construction of an object. Use this to create objects in place inside a `std::optional` or `std::variant`.
55+
- `in_place_type_t` indicates in-place construction of an object of a specific type. This is useful with `std::any` because `std::any` can hold any kind of type, so we need to specify the type it will hold.
56+
- `in_place_index_t` indicates in-place construction of an object at a specific index. Use this with `std::variant` to specify the index where the object is created.
6557

6658
The following are some types that use these structs in their constructors: `expected` class, [`optional` class](optional-class.md), [`single_view` class](single-view-class.md), [`any` class](any-class.md) or [`variant` class](variant-class.md).
6759

@@ -78,30 +70,27 @@ The following are some types that use these structs in their constructors: `expe
7870
struct MyStruct
7971
{
8072
int value;
81-
MyStruct(int v) : value(v)
82-
{
83-
}
73+
MyStruct(int v) : value(v) {}
8474
};
8575

8676
int main()
8777
{
88-
// Uses std::in_place to construct an integer directly inside opt
78+
// Construct a MyStruct directly inside opt
8979
std::optional<MyStruct> opt(std::in_place, MyStruct(42));
9080

91-
// Construct a MyStruct object inside various objects
81+
// Construct a MyStruct object inside an any object
9282
std::any a(std::in_place_type<MyStruct>, MyStruct(314));
9383

94-
// Construct a MyStruct object inside a vector object at index 0
84+
// Construct a MyStruct object inside a vector at index 0
9585
std::variant<MyStruct> v(std::in_place_index<0>, MyStruct(271));
9686

97-
9887
if (opt)
9988
{
10089
std::cout << opt->value << ", ";
10190
}
10291

10392
std::cout << std::any_cast<MyStruct>(a).value << ", "
104-
<< std::get<0>(v).value << std::endl;
93+
<< std::get<0>(v).value;
10594

10695
return 0;
10796
}
@@ -110,3 +99,10 @@ int main()
11099
```output
111100
42, 314, 271
112101
```
102+
## Requirements
103+
104+
**Header:** `<utility>`
105+
106+
**Namespace:** `<utility>`
107+
108+
**Compiler Option:** [`/std:c++17`](../build/reference/std-specify-language-standard-version.md) or later.

‎docs/standard-library/optional-class.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ If *rhs* contains a value, direct initializes the contained value as if using `s
123123
124124
## <a name="optional-destructor"></a> ~optional destructor
125125
126-
Destroys any non-trivially destructible contained value, if one is present, by invoking its destructor.
126+
Destroys any nontrivially destructible contained value, if one is present, by invoking its destructor.
127127
128128
```cpp
129129
~optional();

0 commit comments

Comments
 (0)