Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/utility/in place"

From cppreference.com
< cpp‎ | utility
Line 7: Line 7:
 
     explicit in_place_t() = default;
 
     explicit in_place_t() = default;
 
};
 
};
inline constexpr std::in_place_t in_place{};
+
inline constexpr in_place_t in_place{};
 
}}
 
}}
 
{{dcl | since=c++17 | 1=
 
{{dcl | since=c++17 | 1=

Revision as of 14:07, 15 October 2017

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
Defined in header <utility>
struct in_place_t {

    explicit in_place_t() = default;
};

inline constexpr in_place_t in_place{};
(since C++17)
template <class T> struct in_place_type_t {

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

inline constexpr in_place_type_t<T> in_place_type{};
(since C++17)
template <size_t I> 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{};
(since C++17)

std::in_place, std::in_place_type, and std::in_place_index are 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.

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

See also

(C++17)
a wrapper that may or may not hold an object
(class template) [edit]
(C++17)
a type-safe discriminated union
(class template) [edit]
(C++17)
objects that hold instances of any CopyConstructible type
(class) [edit]