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
は、例外送出版と非例外送出版の
アロケーション関数
のオーバーロードを区別するために使用される空のクラス型です。
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 | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2510 | C++11 | デフォルトコンストラクタが非explicitであり、曖昧性を引き起こす可能性があった | explicitに変更 |
関連項目
|
メモリ確保関数
(関数) |