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

Appends the given element value to the end of the container.

# Declarations

constexpr reference push_back( const T& value );

(since C++26)

constexpr reference push_back( T&& value );

(since C++26)

# Parameters

# Return value

back(), i.e. a reference to the inserted element.

# Example

#include <inplace_vector>
#include <new>
#include <print>
#include <string>
 
int main()
{
    std::inplace_vector<std::string, 2> fauna;
    std::string dog{"\N{DOG}"};
 
    fauna.push_back("\N{CAT}"); // overload (1)
    fauna.push_back(std::move(dog)); // overload (2)
    std::println("fauna = {}", fauna);
 
    try
    {
        fauna.push_back("\N{BUG}"); // throws: there is no space
    }
    catch(const std::bad_alloc& ex)
    {
        std::println("{}", ex.what());
    }
    std::println("fauna = {}", fauna);
}

# See also