A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../../cpp/container/inplace_vector/resize.html below:

std::inplace_vector<T,N>::resize - cppreference.com

#include <inplace_vector>
#include <print>
 
int main()
{
    std::inplace_vector<int, 6> v(6, 9);
    std::println("Initially, v = {}", v);
 
    v.resize(2);
    std::println("After resize(2), v = {}", v);
 
    v.resize(4);
    std::println("After resize(4), v = {}", v);
 
    v.resize(6, -1);
    std::println("After resize(6, -1), v = {}", v);
 
    try
    {
        std::print("Trying resize(13): ");
        v.resize(13); // throws, because count > N; v is left unchanged
    }
    catch(const std::bad_alloc& ex)
    {
        std::println("ex.what(): {}", ex.what());
    }
    std::println("After exception, v = {}", v);
}
Initially, v = [9, 9, 9, 9, 9, 9]
After resize(2), v = [9, 9]
After resize(4), v = [9, 9, 0, 0]
After resize(6, -1), v = [9, 9, 0, 0, -1, -1]
Trying resize(13): ex.what(): std::bad_alloc
After exception, v = [9, 9, 0, 0, -1, -1]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4