diff --git a/docs/standard-library/in-place-t-struct.md b/docs/standard-library/in-place-t-struct.md index 4e2312570f..b7c4cecc59 100644 --- a/docs/standard-library/in-place-t-struct.md +++ b/docs/standard-library/in-place-t-struct.md @@ -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", "utility/std::in_place_t"] -helpviewer_keywords: ["utility 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", "utility/std::in_place_t", "utility/utility", "utility/std::in_place_type_t", "utility", "utility/std::in_place_index_t"] +helpviewer_keywords: ["utility struct", "utility struct", "utility::in_place_type_t struct", "utility 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 - struct in_place_type_t { - explicit in_place_type_t() = default; - }; +struct in_place_type_t +{ + explicit in_place_type_t() = default; +}; -template inline constexpr in_place_type_t in_place_type{}; +template +constexpr in_place_type_t in_place_type{}; template - struct in_place_index_t { - explicit in_place_index_t() = default; - }; +struct in_place_index_t +{ + explicit in_place_index_t() = default; +}; -template inline constexpr in_place_index_t in_place_index{}; +template +constexpr in_place_index_t 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 +#include +#include +#include + +// 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 opt(std::in_place, 29.0, 13.0); + + // Construct a MyStruct object inside an any object + std::any a(std::in_place_type, 3.14); + + // Construct a MyStruct object inside a vector at index 0 + std::variant v(std::in_place_index<0>, 2.718); + + if (opt) + { + std::cout << opt->value << ", "; + } + + std::cout << std::any_cast(a).value << ", " + << std::get<0>(v).value; + + return 0; +} +``` + +```output +42, 3.14, 2.718 +``` + +## Requirements + +**Header:** `` + +**Namespace:** `std` + +**Compiler Option:** [`/std:c++17`](../build/reference/std-specify-language-standard-version.md) or later. \ No newline at end of file diff --git a/docs/standard-library/optional-class.md b/docs/standard-library/optional-class.md index 91889ce7f7..4df0c70b5a 100644 --- a/docs/standard-library/optional-class.md +++ b/docs/standard-library/optional-class.md @@ -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"] --- @@ -11,7 +11,7 @@ The class template `optional` describes an object that may or may not contain When an instance of `optional` 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` 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. @@ -123,7 +123,7 @@ If *rhs* contains a value, direct initializes the contained value as if using `s ## ~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(); diff --git a/docs/standard-library/toc.yml b/docs/standard-library/toc.yml index 12935fdd96..43e6cbcb4e 100644 --- a/docs/standard-library/toc.yml +++ b/docs/standard-library/toc.yml @@ -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: diff --git a/docs/standard-library/utility.md b/docs/standard-library/utility.md index 253764a553..266e984099 100644 --- a/docs/standard-library/utility.md +++ b/docs/standard-library/utility.md @@ -1,27 +1,23 @@ --- description: "Learn more about: " title: "" -ms.date: "11/04/2016" +ms.date: 11/14/2024 f1_keywords: [""] helpviewer_keywords: ["utility header"] -ms.assetid: c4491103-5da9-47a1-9c2b-ed8bc64b0599 --- # `` -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:** \ +**Header:** `` -**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 \ header is automatically included by \ to assist in managing their key/value pair type elements. - -> [!NOTE] -> The \ header uses the statement `#include `. It also refers to `class tuple` as defined in \. +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 @@ -29,57 +25,57 @@ Pairs are widely used in the C++ Standard Library. They are required both as the |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 diff --git a/docs/windows/latest-supported-vc-redist.md b/docs/windows/latest-supported-vc-redist.md index b0bf196730..840af6a36c 100644 --- a/docs/windows/latest-supported-vc-redist.md +++ b/docs/windows/latest-supported-vc-redist.md @@ -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", @@ -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: