std:: nothrow
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Memory management library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Low level memory management
| Functions | ||||
|
(C++11)
|
||||
| Classes | ||||
|
(C++11)
|
||||
|
(C++17)
|
||||
| Types | ||||
| Objects | ||||
|
nothrow
|
||||
|
(C++20)
|
||||
| Object access | ||||
|
(C++17)
|
|
헤더 파일에 정의됨
<new>
|
||
| (1) | ||
|
struct
nothrow_t
{
}
;
|
(C++11 이전) | |
|
struct
nothrow_t
{
explicit
nothrow_t
(
)
=
default
;
}
;
|
(C++11 이후) | |
|
extern
const
std::
nothrow_t
nothrow
;
|
(2) | |
std::nothrow_t
는 throwing 및 non-throwing
allocation functions
의 오버로드를 구분하기 위해 사용되는 빈 클래스 타입입니다.
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로 변경됨 |
참고 항목
|
할당 함수
(함수) |