Scroll to navigation

std::in_place,std::in_place_type,std::in_place_index,std::in_place_t,(3) C++ Standard Libary std::in_place,std::in_place_type,std::in_place_index,std::in_place_t,(3)

NAME

std::in_place,std::in_place_type,std::in_place_index,std::in_place_t, - std::in_place,std::in_place_type,std::in_place_index,std::in_place_t,

Synopsis


Defined in header <utility>
struct in_place_t { explicit in_place_t() = default; }; (1) (since C++17)
inline constexpr std::in_place_t in_place {}; (2) (since C++17)
template< class T > (3) (since C++17)
struct in_place_type_t { explicit in_place_type_t() = default; };
template< class T > (4) (since C++17)
inline constexpr std::in_place_type_t<T> in_place_type {};
template< std::size_t I >
struct in_place_index_t { explicit in_place_index_t() = default; (5) (since C++17)
};
template< std::size_t I > (6) (since C++17)
inline constexpr std::in_place_index_t<I> in_place_index {};


1,3,5) The type/type templates std::in_place_t, std::in_place_type_t and
std::in_place_index_t can be used in the constructor's parameter list to match the
intended tag.
2,4,6) The corresponding std::in_place, std::in_place_type, and std::in_place_index
instances of (1,3,5) are disambiguation tags that can be passed to the constructors
of std::expected, 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.

Standard library


The following standard library vocabulary types use (1-6) as disambiguation tags:


expected a wrapper that contains either an expected or error value
(C++23) (class template)
optional a wrapper that may or may not hold an object
(C++17) (class template)
variant a type-safe discriminated union
(C++17) (class template)
any objects that hold instances of any CopyConstructible type
(C++17) (class)

See also


sorted_unique indicates that elements of a range are sorted and unique
sorted_unique_t (tag)
(C++23)
sorted_equivalent indicates that elements of a range are sorted (uniqueness is not
sorted_equivalent_t required)
(C++23) (tag)

2024.06.10 http://cppreference.com