noexcept

How do I write an ADL-enabled trailing return type, or noexcept specification?

自闭症网瘾萝莉.ら 提交于 2019-11-27 17:58:22
Imagine I'm writing some container template or something. And the time comes to specialize std::swap for it. As a good citizen, I'll enable ADL by doing something like this: template <typename T> void swap(my_template<T>& x, my_template<T>& y) { using std::swap; swap(x.something_that_is_a_T, y.something_that_is_a_T); } This is very neat and all. Until I want to add an exception specification. My swap is noexcept as long as the swap for T is noexcept . So, I'd be writing something like: template <typename T> void swap(my_template<T>& x, my_template<T>& y) noexcept(noexcept(swap(std::declval<T>(

Why vector access operators are not specified as noexcept?

给你一囗甜甜゛ 提交于 2019-11-27 05:35:54
问题 Why std::vector 's operator[] , front and back member functions are not specified as noexcept ? 回答1: The standard's policy on noexcept is to only mark functions that cannot or must not fail, but not those that simply are specified not to throw exceptions. In other words, all functions that have a limited domain (pass the wrong arguments and you get undefined behavior) are not noexcept , even when they are not specified to throw. Functions that get marked are things like swap (must not fail,

noexcept, stack unwinding and performance

自作多情 提交于 2019-11-27 01:01:38
问题 The following draft from Scott Meyers new C++11 book says(page 2, lines 7-21) The difference between unwinding the call stack and possibly unwinding it has a surprisingly large impact on code generation. In a noexcept function, optimizers need not keep the runtime stack in an unwindable state if an exception would propagate out of the function, nor must they ensure that objects in a noexcept function are destroyed in the inverse order of construction should an exception leave the function.

Is there an automatic noexcept specifier?

流过昼夜 提交于 2019-11-26 23:06:48
问题 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. template <class T> void f(T&& t) noexcept(noexcept

How do I write an ADL-enabled trailing return type, or noexcept specification?

久未见 提交于 2019-11-26 22:37:10
问题 Imagine I'm writing some container template or something. And the time comes to specialize std::swap for it. As a good citizen, I'll enable ADL by doing something like this: template <typename T> void swap(my_template<T>& x, my_template<T>& y) { using std::swap; swap(x.something_that_is_a_T, y.something_that_is_a_T); } This is very neat and all. Until I want to add an exception specification. My swap is noexcept as long as the swap for T is noexcept . So, I'd be writing something like:

Difference between C++03 throw() specifier C++11 noexcept

喜你入骨 提交于 2019-11-26 21:28:04
Is there any other difference between throw() and noexcept apart from being checked runtime and compile time respectively ? Wikipedia C++11 article suggests that C++03 throw specifiers are deprecated. Why so, is noexcept capable enough to cover all that at compile time ? [Note: I referred this question and this article , but couldn't got the solid reason of deprecation.] Nicol Bolas Exception specifiers were deprecated because exception specifiers are generally a terrible idea . noexcept was added because it's the one reasonably useful use of an exception specifier: knowing when a function won

When should I really use noexcept?

旧街凉风 提交于 2019-11-26 09:08:49
The noexcept keyword can be appropriately applied to many function signatures, but I am unsure as to when I should consider using it in practice. Based on what I have read so far, the last-minute addition of noexcept seems to address some important issues that arise when move constructors throw. However, I am still unable to provide satisfactory answers to some practical questions that led me to read more about noexcept in the first place. There are many examples of functions that I know will never throw, but for which the compiler cannot determine so on its own. Should I append noexcept to

Difference between C++03 throw() specifier C++11 noexcept

人盡茶涼 提交于 2019-11-26 06:15:38
问题 Is there any other difference between throw() and noexcept apart from being checked runtime and compile time respectively ? Wikipedia C++11 article suggests that C++03 throw specifiers are deprecated. Why so, is noexcept capable enough to cover all that at compile time ? [Note: I referred this question and this article, but couldn\'t got the solid reason of deprecation.] 回答1: Exception specifiers were deprecated because exception specifiers are generally a terrible idea. noexcept was added

When should I really use noexcept?

烂漫一生 提交于 2019-11-26 01:55:24
问题 The noexcept keyword can be appropriately applied to many function signatures, but I am unsure as to when I should consider using it in practice. Based on what I have read so far, the last-minute addition of noexcept seems to address some important issues that arise when move constructors throw. However, I am still unable to provide satisfactory answers to some practical questions that led me to read more about noexcept in the first place. There are many examples of functions that I know will