std::inplace_vector<T,N>::emplace
Min standard notice:
Inserts a new element into the container directly before pos. Typically, the element is constructed uses placement-new to construct the element in-place at the location provided by the container. The arguments args… are forwarded to the constructor as std::forward
# Declarations
template< class... Args >
constexpr iterator emplace( const_iterator position, Args&&... args );
(since C++26)
# Parameters
pos: iterator before which the new element will be constructedargs: arguments to forward to the constructor of the element
# Return value
An iterator to the inserted element.
# Example
#include <cassert>
#include <inplace_vector>
#include <new>
#include <utility>
int main()
{
using P = std::pair<int, int>;
using I = std::inplace_vector<P, 3>;
auto nums = I{{0, 1}, {2, 3}};
auto it = nums.emplace(nums.begin() + 1, -1, -2);
assert((*it == P{-1, -2}));
assert((nums == I{P{0, 1}, {-1, -2}, {2, 3}}));
try
{
nums.emplace(nums.begin(), 1, 3); // throws: no space
}
catch(const std::bad_alloc& ex)
{
std::cout << ex.what() << '\n';
}
}