Namespaces
Variants
Views
Actions

std::in_place, std::in_place_t, std::in_place_type_t, std::in_place_index_t

From cppreference.com
< cpp‎ | utility
Defined in header <utility>
std::in_place_tag in_place( /* unspecified */ );
(1) (since C++17)
template < class T >
std::in_place_tag in_place( /* unspecified */<T> );
(2) (since C++17)
template < std::size_t I >
std::in_place_tag in_place( /* unspecified */<I> );
(3) (since C++17)
using in_place_t = std::in_place_tag (&)( /* unspecified */ );
(since C++17)
template < class T >
using in_place_type_t = std::in_place_tag (&)( /* unspecified */<T> );
(since C++17)
template < std::size_t I >
using in_place_index_t = std::in_place_tag (&)( /* unspecified */<I> );
(since C++17)

The std::in_place function and function templates are special disambiguation tags that can be passed to the constructors of std::optional, std::variant, and std::any to indicate that the contained object should be constructed in-place, and (for the latter two) the type of the object to be constructed.

They are implemented as a set of overloaded function/function templates with a special return type, to allow users to write all of in_place, in_place<T> (with a type), and in_place<I> (with an integral index). The corresponding alias/alias templates in_place_t, in_place_type_t and in_place_index_t can be used in the constructor's parameter list to match the intended tag.

Actually calling any of the in_place functions results in undefined behavior.

[edit] See also

(since C++17)
a wrapper that may or may not hold an object
(class template) [edit]
(since C++17)
a type-safe discriminated union
(class template) [edit]
(since C++17)
Objects that hold instances of any CopyConstructible type.
(class) [edit]
(since C++17)
Special tag type used by the in-place construction tags
(class) [edit]