Skip to content

Repo sync for protected branch #5124

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

Merged
merged 21 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 91 additions & 15 deletions docs/standard-library/in-place-t-struct.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,108 @@
---
description: "Learn more about: in_place_t Struct"
title: "in_place_t Struct"
ms.date: "11/04/2016"
f1_keywords: ["utility<in_place_t>", "utility/std::in_place_t"]
helpviewer_keywords: ["utility<in_place_t> struct"]
description: "Learn more about: in_place_t, in_place_type_t, in_place_index_t"
title: "in_place_t, in_place_type_t, in_place_index_t"
ms.date: 11/14/2024
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"]
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"]
---
# in_place_t Struct
# `in_place_t`, `in_place_type_t`, `in_place_index_t` struct

Introduced in C++17.

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.

## Syntax

```cpp
struct in_place_t {
struct in_place_t
{
explicit in_place_t() = default;
};

inline constexpr in_place_t in_place{};

template <class T>
struct in_place_type_t {
explicit in_place_type_t() = default;
};
struct in_place_type_t
{
explicit in_place_type_t() = default;
};

template <class T> inline constexpr in_place_type_t<T> in_place_type{};
template <class T>
constexpr in_place_type_t<T> in_place_type{};

template <size_t I>
struct in_place_index_t {
explicit in_place_index_t() = default;
};
struct in_place_index_t
{
explicit in_place_index_t() = default;
};

template <size_t I> inline constexpr in_place_index_t<I> in_place_index{};
template <size_t I>
constexpr in_place_index_t<I> in_place_index{};
```

## Parameters

*`I`*\
The index where the object is created in place.

*`T`*\
The type of object to create.

## Remarks

- `in_place_t` indicates in-place construction of an object. Used to create objects in place inside a `std::optional`.
- `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.
- `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.

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).

## Example

```cpp
#include <iostream>
#include <optional>
#include <any>
#include <variant>

// compile with /std:c++17

struct MyStruct
{
double value;
MyStruct(double v0, double v1 = 0) : value(v0 + v1) {}
};

int main()
{
// Construct a MyStruct directly inside opt
std::optional<MyStruct> opt(std::in_place, 29.0, 13.0);

// Construct a MyStruct object inside an any object
std::any a(std::in_place_type<MyStruct>, 3.14);

// Construct a MyStruct object inside a vector at index 0
std::variant<MyStruct, int> v(std::in_place_index<0>, 2.718);

if (opt)
{
std::cout << opt->value << ", ";
}

std::cout << std::any_cast<MyStruct>(a).value << ", "
<< std::get<0>(v).value;

return 0;
}
```

```output
42, 3.14, 2.718
```

## Requirements

**Header:** `<utility>`

**Namespace:** `std`

**Compiler Option:** [`/std:c++17`](../build/reference/std-specify-language-standard-version.md) or later.
6 changes: 3 additions & 3 deletions docs/standard-library/optional-class.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: "Learn more about: optional Class"
title: "optional Class"
ms.date: "11/04/2016"
ms.date: 11/14/2024
f1_keywords: ["optional/std::optional", "optional/std::optional::has_value", "optional/std::optional::reset", "optional/std::optional::value", "optional/std::optional::value_or"]
helpviewer_keywords: ["optional/std::optional", "optional/std::optional::has_value", "optional/std::optional::reset", "optional/std::optional::value", "optional/std::optional::value_or"]
---
Expand All @@ -11,7 +11,7 @@ The class template `optional<T>` describes an object that may or may not contain

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`**.

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.
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.

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

Expand Down Expand Up @@ -123,7 +123,7 @@ If *rhs* contains a value, direct initializes the contained value as if using `s

## <a name="optional-destructor"></a> ~optional destructor

Destroys any non-trivially destructible contained value, if one is present, by invoking its destructor.
Destroys the contained value, if one is present.

```cpp
~optional();
Expand Down
2 changes: 2 additions & 0 deletions docs/standard-library/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1447,6 +1447,8 @@ items:
href: utility-operators.md
- name: identity struct
href: identity-structure.md
- name: in_place_t, in_place_type_t, in_place_index_t struct
href: in-place-t-struct.md
- name: pair struct
href: pair-structure.md
- name: <valarray>
Expand Down
76 changes: 36 additions & 40 deletions docs/standard-library/utility.md
Original file line number Diff line number Diff line change
@@ -1,85 +1,81 @@
---
description: "Learn more about: <utility>"
title: "<utility>"
ms.date: "11/04/2016"
ms.date: 11/14/2024
f1_keywords: ["<utility>"]
helpviewer_keywords: ["utility header"]
ms.assetid: c4491103-5da9-47a1-9c2b-ed8bc64b0599
---
# `<utility>`

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.
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.

## Requirements

**Header:** \<utility>
**Header:** `<utility>`

**Namespace:** std
**Namespace:** `std`

## Remarks

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.

> [!NOTE]
> The \<utility> header uses the statement `#include <initializer_list>`. It also refers to `class tuple` as defined in \<tuple>.
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).

## Members

### Classes

|Type|Description|
|-|-|
|[chars_format](../standard-library/chars-format-class.md)|Floating-point format for primitive numerical conversion.|
|[tuple_element](../standard-library/tuple-element-class-tuple.md)|A class that wraps the type of a `pair` element.|
|[tuple_size](../standard-library/tuple-size-class-tuple.md)|A class that wraps `pair` element count.|
|[`chars_format`](../standard-library/chars-format-class.md)|Floating-point format for primitive numerical conversion.|
|[`tuple_element`](../standard-library/tuple-element-class-tuple.md)|Wraps the type of a `pair` element.|
|[`tuple_size`](../standard-library/tuple-size-class-tuple.md)|Wraps a `pair` element count.|

### Objects

|Template|Description|
|-|-|
|[index_sequence](../standard-library/utility-functions.md#index_sequence)|An alias template defined for the common case where `T` is `std::size_t` |
|[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|
|[make_index_sequence](../standard-library/utility-functions.md#make_index_sequence)| Helper alias template to simplify the creation of a `std::index_sequence` type. |
|[make_integer_sequence](../standard-library/utility-functions.md#make_integer_sequence)|Helper alias template to simplify the creation of a `std::integer_sequence` type.|
|[`index_sequence`](../standard-library/utility-functions.md#index_sequence)|An alias template defined for the common case where `T` is `std::size_t` |
|[`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|
|[`make_index_sequence`](../standard-library/utility-functions.md#make_index_sequence)| Helper alias template to simplify the creation of a `std::index_sequence` type. |
|[`make_integer_sequence`](../standard-library/utility-functions.md#make_integer_sequence)|Helper alias template to simplify the creation of a `std::integer_sequence` type.|

### Functions

|Function|Description|
|-|-|
|[as_const](../standard-library/utility-functions.md#asconst)|Returns type.|
|[declval](../standard-library/utility-functions.md#declval)|Shorthand expression evaluation.|
|[exchange](../standard-library/utility-functions.md#exchange)|Assigns a new value to an object and returns its old value.|
|[forward](../standard-library/utility-functions.md#forward)|Preserves the reference type (either `lvalue` or `rvalue`) of the argument from being obscured by perfect forwarding.|
|[from_chars](../standard-library/utility-functions.md#from_chars)||
|[get](../standard-library/utility-functions.md#get)|A function that gets an element from a `pair` object.|
|[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.|
|[move](../standard-library/utility-functions.md#move)|Returns the passed in argument as an `rvalue` reference.|
|[move_if_noexcept](../standard-library/utility-functions.md#moveif)||
|[swap](../standard-library/utility-functions.md#swap)|Exchanges the elements of two `pair` objects.|
|[to_chars](../standard-library/utility-functions.md#to_chars)|Converts value into a character string.|
|[`as_const`](../standard-library/utility-functions.md#asconst)|Returns type.|
|[`declval`](../standard-library/utility-functions.md#declval)|Shorthand expression evaluation.|
|[`exchange`](../standard-library/utility-functions.md#exchange)|Assigns a new value to an object and returns its old value.|
|[`forward`](../standard-library/utility-functions.md#forward)|Preserves the reference type (either `lvalue` or `rvalue`) of the argument from being obscured by perfect forwarding.|
|[`from_chars`](../standard-library/utility-functions.md#from_chars)||
|[`get`](../standard-library/utility-functions.md#get)|A function that gets an element from a `pair` object.|
|[`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.|
|[`move`](../standard-library/utility-functions.md#move)|Returns the passed in argument as an `rvalue` reference.|
|[`move_if_noexcept`](../standard-library/utility-functions.md#moveif)||
|[`swap`](../standard-library/utility-functions.md#swap)|Exchanges the elements of two `pair` objects.|
|[`to_chars`](../standard-library/utility-functions.md#to_chars)|Converts value into a character string.|

### Operators

|Operator|Description|
|-|-|
|[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.|
|[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.|
|[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.|
|[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.|
|[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.|
|[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.|
|[`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.|
|[`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.|
|[`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.|
|[`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.|
|[`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.|
|[`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.|

### Structs

|Struct|Description|
|-|-|
|[from_chars_result](../standard-library/from-chars-result-structure.md)|A struct used for `from_chars`.|
|[identity](../standard-library/identity-structure.md)|A struct that provides a type definition as the template parameter.|
|[in_place_t](../standard-library/in-place-t-struct.md)|Also includes structs `in_place_type_t` and `in_place_index_t`.|
|[integer_sequence](../standard-library/integer-sequence-class.md)|Represents an integer sequence.|
|[pair](../standard-library/pair-structure.md)|A type that provides for the ability to treat two objects as a single object.|
|[piecewise_construct_t](../standard-library/piecewise-construct-t-structure.md)|A type used to keep separate constructor and function overloading.|
|[to_chars_result](../standard-library/to-chars-result-structure.md)|A struct used for `to_chars`.|
|[`from_chars_result`](../standard-library/from-chars-result-structure.md)|A struct used for `from_chars`.|
|[`identity`](../standard-library/identity-structure.md)|A struct that provides a type definition as the template parameter.|
|[`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.|
|[`integer_sequence`](../standard-library/integer-sequence-class.md)|Represents an integer sequence.|
|[`pair`](../standard-library/pair-structure.md)|A type that provides for the ability to treat two objects as a single object.|
|[`piecewise_construct_t`](../standard-library/piecewise-construct-t-structure.md)|A type used to keep separate constructor and function overloading.|
|[`to_chars_result`](../standard-library/to-chars-result-structure.md)|A struct used for `to_chars`.|

## See also

Expand Down
4 changes: 2 additions & 2 deletions docs/windows/latest-supported-vc-redist.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Latest supported Visual C++ Redistributable downloads"
description: "This article lists the download links for the latest versions of Visual C++ Redistributable packages."
ms.date: 5/28/2024
ms.date: 11/15/2024
helpviewer_keywords:
[
"redist",
Expand Down Expand Up @@ -29,7 +29,7 @@ Unlike older versions of Visual Studio, which have infrequent redist updates, th

## Latest Microsoft Visual C++ Redistributable Version

The latest version is `14.40.33816.0`
The latest version is `14.42.34433.0`

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

Expand Down