Namespaces
Variants
Views
Actions

std::inplace_vector<T,N>::try_emplace_back

From cppreference.com
< cpp‎ | container‎ | inplace vector
Revision as of 14:42, 26 August 2024 by Space Mission (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
 
 
template< class... Args >
constexpr pointer try_emplace_back( Args&&... args );
(since C++26)

Conditionally appends an object of type T to the end of the container.

If size() == capacity() is true, there are no effects. Otherwise, appends direct-non-list-initialized with std::forward<Args>(args)... object of type T.

No iterators or references are invalidated, except end(), which is invalidated if the insertion occurs.

Contents

Parameters

args - arguments to forward to the constructor of the element
Type requirements
-
T must be EmplaceConstructible into inplace_vector from std::forward<Args>(args)....

Return value

std::addressof(back()) if size() < capacity(), nullptr otherwise.

Complexity

Constant.

Exceptions

Any exception thrown by initialization of inserted element. If an exception is thrown for any reason, this function has no effect (strong exception safety guarantee).

Notes

Example

See also

constructs an element in-place at the end
(public member function) [edit]
adds an element to the end
(public member function) [edit]
adds a range of elements to the end
(public member function) [edit]
tries to add a range of elements to the end
(public member function) [edit]
unconditionally constructs an element in-place at the end
(public member function) [edit]
unconditionally adds an element to the end
(public member function) [edit]
removes the last element
(public member function) [edit]
creates a std::back_insert_iterator of type inferred from the argument
(function template) [edit]