問題タブ [noexcept]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 無効化された例外と noexcept()
std::swap
は次のように宣言されています。
プログラムで例外を無効にすると ( g++ の場合と同様-fno-exceptions
) 、カスタムstd::swap
型が noexcept であるかどうかに関係なく、移動が有効になっている場合、カスタム型に対して移動操作が使用されますか?
編集:フォローアップの質問:
std::swap は、私のタイプに移動がある場合は常に移動を使用することに気付いた後、私の本当の質問は、次のような特性に何が起こるis_nothrow_move_assignable<>
かです ?
型に移動操作std::vector
がある場合、再割り当て時に常に移動を使用しますか?noexcept(true)
c++ - Is there an automatic noexcept specifier?
I've heard that noexcept
keyword is more like 'it should never throw an exception' rather than 'it doesn't'.
I don't think it's good to use noexcept
keyword if I'm not sure it throws an exception or not, but noexcept
keyword is sometimes related to the performance like in a move constructor.
So I tried to use noexcept
qualifiers, but it gets harder if it has multiple statements in the definition and it becomes a kind of copy-and-paste thing.
I think the compiler can figure out whether the definition of a function consists of non-throwing statements, so it will be easier to utilize noexcept
if there's an expression like noexcept(auto)
, but it seems that there is no such thing in the standard.
Is there any way to simplify the noexcept expression?
c++ - 関数テンプレートの T の代入演算子が例外をスローするかどうかを調べる方法は?
ここに私の関数テンプレートがあります:
=
の代入演算子が指定されT
ている場合、この関数が例外をスローしないように指定したいと思いますnoexcept
。これを行う方法はありますか?
c++ - std::is_nothrow_move_assignable がデストラクタの存在に依存するのはなぜですか?
次のようなクラスがあります。
示されている 2 つの特別なメンバー関数は、宣言されている唯一のものです。
今、
すべて満足しています。まだ、
主張します。空のデストラクタを削除すると、パスします。
デストラクタは移動代入演算子とどのような関係がありますか? 5つの新しいルール?
コンパイラは GCC 4.9.3 です-std=c++0x
(歴史的な理由から)。
c++ - noexcept に関する混乱
多くのビデオを見たり、本を読んだりした後、いつ、いつ noexcept を使用しないかについてよくわかりません。
すべての本は、関数が決してスローしない場合にのみ noexcept を使用するべきだと言っています。
それ以外で使うべきだと思います。割り当てる関数は noexcept であってはならないと多くの人が言いますが、これらのエラーをキャッチしたくなくて、への呼び出しstd::terminate
が許容される場合はどうすればよいでしょうか?
つまり、スローしない関数、または例外をキャッチしたい関数を除くすべての関数で noexcept を使用する必要があります。
IMHO 一部の例外はキャッチする必要はありません (つまり、メモリ不足など)
c++ - データメンバーに依存するC++のnoexcept仕様
この宣言は問題ありません:
のために
MyClass に functor データ メンバーがあるとします。
前のケースと同じように noexcept 仕様を書きたいので、これを試しました。
しかし、コンパイラは、ファンクターがスコープではないことを教えてくれます。以下は、同様の理由で機能しません。
また、デフォルトのコンストラクターがない T として使用されるクラスがいくつかあるため、以下は機能しません。
以下は構文的に間違っています。
それは私が欲しいものを絵でよく説明していますが。
なにか提案を?とりあえず仕様は諦めました…
c++ - std::function で「noexcept」を強制しますか?
このコードはコンパイルおよび実行され、以下をスローしint
ます。
ただし、関数のみを渡す必要があるr(foo);
ため、コンパイラーに行を拒否してもらいたいと思います。指定子は無視されているようです。それを達成する方法はありますか?r
noexcept
noexcept
編集:この質問は、関数ポインターを渡すときに noexcept-ness に関する知識が転送されることになっていますか? とは異なります。特に の場合、私は救済を求めているからですstd::function
。