Namespaces
Variants

std::nothrow

cppreference.net에서
< cpp | memory | new
(cpp/memory/new/nothrow t에서 넘어옴)
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 폐지됨)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
교체 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
메모리 관리 라이브러리
할당자
메모리 자원
초기화되지 않은 저장소 (C++20까지*)
가비지 컬렉터 지원 (C++23까지)
 
 
헤더 <new>
struct nothrow_t {};
에 정의됨 (1) (C++11까지)
struct nothrow_t { explicit nothrow_t() = default; };
(C++11부터)
extern const std::nothrow_t nothrow;
(2)

std::nothrow_t은 던짐 및 던지지 않는 할당 함수의 오버로드를 구별하는 데 사용되는 빈 클래스 타입입니다. std::nothrow은 이것의 상수입니다.

예제

#include <iostream>
#include <new>
int main()
{
    try
    {
        while (true)
        {
            new int[100000000ul];   // throwing overload
        }
    }
    catch (const std::bad_alloc& e)
    {
        std::cout << e.what() << '\n';
    }
    while (true)
    {
        int* p = new(std::nothrow) int[100000000ul]; // non-throwing overload
        if (p == nullptr)
        {
            std::cout << "Allocation returned nullptr\n";
            break;
        }
    }
}

출력:

std::bad_alloc
Allocation returned nullptr

결함 보고서

다음의 동작 변경 결함 보고서들은 이전에 발표된 C++ 표준에 소급 적용되었습니다.

DR 적용 대상 게시된 동작 올바른 동작
LWG 2510 C++11 기본 생성자가 non-explicit였으며, 이는 모호성을 초래할 수 있었음 explicit로 변경됨

참고 항목

할당 함수
(함수)