Skip to content

Commit d441524

Browse files
Merge pull request #5124 from MicrosoftDocs/main638672923510494684sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 5fb0864 + 82c90d0 commit d441524

File tree

5 files changed

+134
-60
lines changed

5 files changed

+134
-60
lines changed
Lines changed: 91 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,108 @@
11
---
2-
description: "Learn more about: in_place_t Struct"
3-
title: "in_place_t Struct"
4-
ms.date: "11/04/2016"
5-
f1_keywords: ["utility<in_place_t>", "utility/std::in_place_t"]
6-
helpviewer_keywords: ["utility<in_place_t> struct"]
2+
description: "Learn more about: in_place_t, in_place_type_t, in_place_index_t"
3+
title: "in_place_t, in_place_type_t, in_place_index_t"
4+
ms.date: 11/14/2024
5+
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"]
6+
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"]
77
---
8-
# in_place_t Struct
8+
# `in_place_t`, `in_place_type_t`, `in_place_index_t` struct
9+
10+
Introduced in C++17.
11+
12+
The `in_place_t`, `in_place_type_t`, and `in_place_index_t` tag types are used to select the overloaded constructor that creates the object in place in the desired way. For the types that use these tag types, they can also help avoid temporary copy or move operations.
913

1014
## Syntax
1115

1216
```cpp
13-
struct in_place_t {
17+
struct in_place_t
18+
{
1419
explicit in_place_t() = default;
1520
};
1621

1722
inline constexpr in_place_t in_place{};
1823

1924
template <class T>
20-
struct in_place_type_t {
21-
explicit in_place_type_t() = default;
22-
};
25+
struct in_place_type_t
26+
{
27+
explicit in_place_type_t() = default;
28+
};
2329

24-
template <class T> inline constexpr in_place_type_t<T> in_place_type{};
30+
template <class T>
31+
constexpr in_place_type_t<T> in_place_type{};
2532

2633
template <size_t I>
27-
struct in_place_index_t {
28-
explicit in_place_index_t() = default;
29-
};
34+
struct in_place_index_t
35+
{
36+
explicit in_place_index_t() = default;
37+
};
3038

31-
template <size_t I> inline constexpr in_place_index_t<I> in_place_index{};
39+
template <size_t I>
40+
constexpr in_place_index_t<I> in_place_index{};
3241
```
42+
43+
## Parameters
44+
45+
*`I`*\
46+
The index where the object is created in place.
47+
48+
*`T`*\
49+
The type of object to create.
50+
51+
## Remarks
52+
53+
- `in_place_t` indicates in-place construction of an object. Used to create objects in place inside a `std::optional`.
54+
- `in_place_type_t` indicates in-place construction of an object of a specific type. It's useful with `std::any` because `std::any` can hold any kind of type, so we need to specify the type it holds.
55+
- `in_place_index_t` indicates in-place construction of an object at a specific index. Use with `std::variant` to specify the index where the object is created.
56+
57+
The following class types use these structs in their constructors: `expected`, [`optional`](optional-class.md), [`single_view`](single-view-class.md), [`any`](any-class.md) or [`variant`](variant-class.md).
58+
59+
## Example
60+
61+
```cpp
62+
#include <iostream>
63+
#include <optional>
64+
#include <any>
65+
#include <variant>
66+
67+
// compile with /std:c++17
68+
69+
struct MyStruct
70+
{
71+
double value;
72+
MyStruct(double v0, double v1 = 0) : value(v0 + v1) {}
73+
};
74+
75+
int main()
76+
{
77+
// Construct a MyStruct directly inside opt
78+
std::optional<MyStruct> opt(std::in_place, 29.0, 13.0);
79+
80+
// Construct a MyStruct object inside an any object
81+
std::any a(std::in_place_type<MyStruct>, 3.14);
82+
83+
// Construct a MyStruct object inside a vector at index 0
84+
std::variant<MyStruct, int> v(std::in_place_index<0>, 2.718);
85+
86+
if (opt)
87+
{
88+
std::cout << opt->value << ", ";
89+
}
90+
91+
std::cout << std::any_cast<MyStruct>(a).value << ", "
92+
<< std::get<0>(v).value;
93+
94+
return 0;
95+
}
96+
```
97+
98+
```output
99+
42, 3.14, 2.718
100+
```
101+
102+
## Requirements
103+
104+
**Header:** `<utility>`
105+
106+
**Namespace:** `std`
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about: optional Class"
33
title: "optional Class"
4-
ms.date: "11/04/2016"
4+
ms.date: 11/14/2024
55
f1_keywords: ["optional/std::optional", "optional/std::optional::has_value", "optional/std::optional::reset", "optional/std::optional::value", "optional/std::optional::value_or"]
66
helpviewer_keywords: ["optional/std::optional", "optional/std::optional::has_value", "optional/std::optional::reset", "optional/std::optional::value", "optional/std::optional::value_or"]
77
---
@@ -11,7 +11,7 @@ The class template `optional<T>` describes an object that may or may not contain
1111

1212
When an instance of `optional<T>` contains a value, the contained value is allocated within the storage of the `optional` object, in a region suitably aligned for type `T`. When an `optional<T>` is converted to **`bool`**, the result is **`true`** if the object contains a value; otherwise, it's **`false`**.
1313

14-
The contained object type `T` must not be [in_place_t](in-place-t-struct.md) or [nullopt_t](nullopt-t-structure.md). `T` must be *destructible*, that is, its destructor must reclaim all owned resources, and may throw no exceptions.
14+
The contained object type `T` must not be [`in_place_t`](in-place-t-struct.md) or [`nullopt_t`](nullopt-t-structure.md). `T` must be *destructible*, that is, its destructor must reclaim all owned resources, and may throw no exceptions.
1515

1616
The `optional` class is new in C++17.
1717

@@ -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 the contained value, if one is present.
127127
128128
```cpp
129129
~optional();

docs/standard-library/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,8 @@ items:
14471447
href: utility-operators.md
14481448
- name: identity struct
14491449
href: identity-structure.md
1450+
- name: in_place_t, in_place_type_t, in_place_index_t struct
1451+
href: in-place-t-struct.md
14501452
- name: pair struct
14511453
href: pair-structure.md
14521454
- name: <valarray>

docs/standard-library/utility.md

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,81 @@
11
---
22
description: "Learn more about: <utility>"
33
title: "<utility>"
4-
ms.date: "11/04/2016"
4+
ms.date: 11/14/2024
55
f1_keywords: ["<utility>"]
66
helpviewer_keywords: ["utility header"]
7-
ms.assetid: c4491103-5da9-47a1-9c2b-ed8bc64b0599
87
---
98
# `<utility>`
109

11-
Defines C++ Standard Library types, functions, and operators that help to construct and manage pairs of objects, which are useful whenever two objects need to be treated as if they were one.
10+
Defines C++ Standard Library types, functions, and operators that help to construct and manage pairs of objects, which are useful whenever two objects should be treated as if they were one.
1211

1312
## Requirements
1413

15-
**Header:** \<utility>
14+
**Header:** `<utility>`
1615

17-
**Namespace:** std
16+
**Namespace:** `std`
1817

1918
## Remarks
2019

21-
Pairs are widely used in the C++ Standard Library. They are required both as the arguments and return values for various functions and as element types for containers such as [map class](../standard-library/map-class.md) and [multimap class](../standard-library/multimap-class.md). The \<utility> header is automatically included by \<map> to assist in managing their key/value pair type elements.
22-
23-
> [!NOTE]
24-
> The \<utility> header uses the statement `#include <initializer_list>`. It also refers to `class tuple` as defined in \<tuple>.
20+
Pairs are widely used in the C++ Standard Library. They're required both as the arguments and return values for various functions and as element types for associative containers like [`map`](../standard-library/map-class.md) and [`multimap`](../standard-library/multimap-class.md).
2521

2622
## Members
2723

2824
### Classes
2925

3026
|Type|Description|
3127
|-|-|
32-
|[chars_format](../standard-library/chars-format-class.md)|Floating-point format for primitive numerical conversion.|
33-
|[tuple_element](../standard-library/tuple-element-class-tuple.md)|A class that wraps the type of a `pair` element.|
34-
|[tuple_size](../standard-library/tuple-size-class-tuple.md)|A class that wraps `pair` element count.|
28+
|[`chars_format`](../standard-library/chars-format-class.md)|Floating-point format for primitive numerical conversion.|
29+
|[`tuple_element`](../standard-library/tuple-element-class-tuple.md)|Wraps the type of a `pair` element.|
30+
|[`tuple_size`](../standard-library/tuple-size-class-tuple.md)|Wraps a `pair` element count.|
3531

3632
### Objects
3733

3834
|Template|Description|
3935
|-|-|
40-
|[index_sequence](../standard-library/utility-functions.md#index_sequence)|An alias template defined for the common case where `T` is `std::size_t` |
41-
|[index_sequence_for](../standard-library/utility-functions.md#index_sequence_for)|Helper alias template to convert any type parameter pack into an index sequence of the same length|
42-
|[make_index_sequence](../standard-library/utility-functions.md#make_index_sequence)| Helper alias template to simplify the creation of a `std::index_sequence` type. |
43-
|[make_integer_sequence](../standard-library/utility-functions.md#make_integer_sequence)|Helper alias template to simplify the creation of a `std::integer_sequence` type.|
36+
|[`index_sequence`](../standard-library/utility-functions.md#index_sequence)|An alias template defined for the common case where `T` is `std::size_t` |
37+
|[`index_sequence_for`](../standard-library/utility-functions.md#index_sequence_for)|Helper alias template to convert any type parameter pack into an index sequence of the same length|
38+
|[`make_index_sequence`](../standard-library/utility-functions.md#make_index_sequence)| Helper alias template to simplify the creation of a `std::index_sequence` type. |
39+
|[`make_integer_sequence`](../standard-library/utility-functions.md#make_integer_sequence)|Helper alias template to simplify the creation of a `std::integer_sequence` type.|
4440

4541
### Functions
4642

4743
|Function|Description|
4844
|-|-|
49-
|[as_const](../standard-library/utility-functions.md#asconst)|Returns type.|
50-
|[declval](../standard-library/utility-functions.md#declval)|Shorthand expression evaluation.|
51-
|[exchange](../standard-library/utility-functions.md#exchange)|Assigns a new value to an object and returns its old value.|
52-
|[forward](../standard-library/utility-functions.md#forward)|Preserves the reference type (either `lvalue` or `rvalue`) of the argument from being obscured by perfect forwarding.|
53-
|[from_chars](../standard-library/utility-functions.md#from_chars)||
54-
|[get](../standard-library/utility-functions.md#get)|A function that gets an element from a `pair` object.|
55-
|[make_pair](../standard-library/utility-functions.md#make_pair)|A template helper function used to construct objects of type `pair`, where the component types are based on the data types passed as parameters.|
56-
|[move](../standard-library/utility-functions.md#move)|Returns the passed in argument as an `rvalue` reference.|
57-
|[move_if_noexcept](../standard-library/utility-functions.md#moveif)||
58-
|[swap](../standard-library/utility-functions.md#swap)|Exchanges the elements of two `pair` objects.|
59-
|[to_chars](../standard-library/utility-functions.md#to_chars)|Converts value into a character string.|
45+
|[`as_const`](../standard-library/utility-functions.md#asconst)|Returns type.|
46+
|[`declval`](../standard-library/utility-functions.md#declval)|Shorthand expression evaluation.|
47+
|[`exchange`](../standard-library/utility-functions.md#exchange)|Assigns a new value to an object and returns its old value.|
48+
|[`forward`](../standard-library/utility-functions.md#forward)|Preserves the reference type (either `lvalue` or `rvalue`) of the argument from being obscured by perfect forwarding.|
49+
|[`from_chars`](../standard-library/utility-functions.md#from_chars)||
50+
|[`get`](../standard-library/utility-functions.md#get)|A function that gets an element from a `pair` object.|
51+
|[`make_pair`](../standard-library/utility-functions.md#make_pair)|A template helper function used to construct objects of type `pair`, where the component types are based on the data types passed as parameters.|
52+
|[`move`](../standard-library/utility-functions.md#move)|Returns the passed in argument as an `rvalue` reference.|
53+
|[`move_if_noexcept`](../standard-library/utility-functions.md#moveif)||
54+
|[`swap`](../standard-library/utility-functions.md#swap)|Exchanges the elements of two `pair` objects.|
55+
|[`to_chars`](../standard-library/utility-functions.md#to_chars)|Converts value into a character string.|
6056

6157
### Operators
6258

6359
|Operator|Description|
6460
|-|-|
65-
|[operator!=](../standard-library/utility-operators.md#op_neq)|Tests if the pair object on the left side of the operator is not equal to the pair object on the right side.|
66-
|[operator==](../standard-library/utility-operators.md#op_eq_eq)|Tests if the pair object on the left side of the operator is equal to the pair object on the right side.|
67-
|[operator\<](../standard-library/utility-operators.md#op_lt)|Tests if the pair object on the left side of the operator is less than the pair object on the right side.|
68-
|[operator\<=](../standard-library/utility-operators.md#op_gt_eq)|Tests if the pair object on the left side of the operator is less than or equal to the pair object on the right side.|
69-
|[operator>](../standard-library/utility-operators.md#op_gt)|Tests if the pair object on the left side of the operator is greater than the pair object on the right side.|
70-
|[operator>=](../standard-library/utility-operators.md#op_gt_eq)|Tests if the pair object on the left side of the operator is greater than or equal to the pair object on the right side.|
61+
|[`operator!=`](../standard-library/utility-operators.md#op_neq)|Tests if the pair object on the left side of the operator isn't equal to the pair object on the right side.|
62+
|[`operator==`](../standard-library/utility-operators.md#op_eq_eq)|Tests if the pair object on the left side of the operator is equal to the pair object on the right side.|
63+
|[`operator<`](../standard-library/utility-operators.md#op_lt)|Tests if the pair object on the left side of the operator is less than the pair object on the right side.|
64+
|[`operator<=`](../standard-library/utility-operators.md#op_gt_eq)|Tests if the pair object on the left side of the operator is less than or equal to the pair object on the right side.|
65+
|[`operator>`](../standard-library/utility-operators.md#op_gt)|Tests if the pair object on the left side of the operator is greater than the pair object on the right side.|
66+
|[`operator>=`](../standard-library/utility-operators.md#op_gt_eq)|Tests if the pair object on the left side of the operator is greater than or equal to the pair object on the right side.|
7167

7268
### Structs
7369

7470
|Struct|Description|
7571
|-|-|
76-
|[from_chars_result](../standard-library/from-chars-result-structure.md)|A struct used for `from_chars`.|
77-
|[identity](../standard-library/identity-structure.md)|A struct that provides a type definition as the template parameter.|
78-
|[in_place_t](../standard-library/in-place-t-struct.md)|Also includes structs `in_place_type_t` and `in_place_index_t`.|
79-
|[integer_sequence](../standard-library/integer-sequence-class.md)|Represents an integer sequence.|
80-
|[pair](../standard-library/pair-structure.md)|A type that provides for the ability to treat two objects as a single object.|
81-
|[piecewise_construct_t](../standard-library/piecewise-construct-t-structure.md)|A type used to keep separate constructor and function overloading.|
82-
|[to_chars_result](../standard-library/to-chars-result-structure.md)|A struct used for `to_chars`.|
72+
|[`from_chars_result`](../standard-library/from-chars-result-structure.md)|A struct used for `from_chars`.|
73+
|[`identity`](../standard-library/identity-structure.md)|A struct that provides a type definition as the template parameter.|
74+
|[`in_place_t`, `in_place_type_t`, `in_place_index_t`](../standard-library/in-place-t-struct.md)| Indicates how to create an object in place.|
75+
|[`integer_sequence`](../standard-library/integer-sequence-class.md)|Represents an integer sequence.|
76+
|[`pair`](../standard-library/pair-structure.md)|A type that provides for the ability to treat two objects as a single object.|
77+
|[`piecewise_construct_t`](../standard-library/piecewise-construct-t-structure.md)|A type used to keep separate constructor and function overloading.|
78+
|[`to_chars_result`](../standard-library/to-chars-result-structure.md)|A struct used for `to_chars`.|
8379

8480
## See also
8581

docs/windows/latest-supported-vc-redist.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Latest supported Visual C++ Redistributable downloads"
33
description: "This article lists the download links for the latest versions of Visual C++ Redistributable packages."
4-
ms.date: 5/28/2024
4+
ms.date: 11/15/2024
55
helpviewer_keywords:
66
[
77
"redist",
@@ -29,7 +29,7 @@ Unlike older versions of Visual Studio, which have infrequent redist updates, th
2929

3030
## Latest Microsoft Visual C++ Redistributable Version
3131

32-
The latest version is `14.40.33816.0`
32+
The latest version is `14.42.34433.0`
3333

3434
Use the following links to download this version for each supported architecture:
3535

0 commit comments

Comments
 (0)