exception-specification

Is there any point in declaring a deleted function as noexcept?

二次信任 提交于 2019-12-01 15:43:09
Consider these two possible definitions for a class: Exhibit A: struct A { A() = delete; }; Exhibit A′: struct A { A() noexcept = delete; } Is there any point in declaring a deleted function as noexcept ? (Posted this initially as a comment, but encouraged to post as an answer.) Simply, no. A function that is deleted cannot be called (or, in the case of a constructor, used to initialise an object) let alone throw an exception. Edit: hvd mentioned in comments below that noexcept(f()) does not call f() . If the constructor of class A is delete d, then noexcept(A()) will fail to compile,

Is there any point in declaring a deleted function as noexcept?

萝らか妹 提交于 2019-12-01 14:33:09
问题 Consider these two possible definitions for a class: Exhibit A: struct A { A() = delete; }; Exhibit A′: struct A { A() noexcept = delete; } Is there any point in declaring a deleted function as noexcept ? 回答1: (Posted this initially as a comment, but encouraged to post as an answer.) Simply, no. A function that is deleted cannot be called (or, in the case of a constructor, used to initialise an object) let alone throw an exception. Edit: hvd mentioned in comments below that noexcept(f()) does

Is there a generally accepted idiom for indicating C++ code can throw exceptions?

混江龙づ霸主 提交于 2019-11-30 05:10:26
I have seen problems when using C++ code that, unexpectedly to the caller, throws an exception. It's not always possible or practical to read every line of a module that you are using to see if it throws exceptions and if so, what type of exception. Are there established idioms or "best practices" that exist for dealing with this problem? I've thought of the following: In our doxygen documentation, we could add a comment in every function that is expected to throw an exception and it's type(s). Pluses: Simple. Minuses: Subject to user error. We could have an app-wide try/catch(...) for safety.

Is there a generally accepted idiom for indicating C++ code can throw exceptions?

三世轮回 提交于 2019-11-29 02:59:28
问题 I have seen problems when using C++ code that, unexpectedly to the caller, throws an exception. It's not always possible or practical to read every line of a module that you are using to see if it throws exceptions and if so, what type of exception. Are there established idioms or "best practices" that exist for dealing with this problem? I've thought of the following: In our doxygen documentation, we could add a comment in every function that is expected to throw an exception and it's type(s

Questions about Hinnant's stack allocator

旧街凉风 提交于 2019-11-27 03:13:24
I've been using Howard Hinnant's stack allocator and it works like a charm, but some details of the implementation are a little unclear to me. Why are global operators new and delete used? The allocate() and deallocate() member functions use ::operator new and ::operator delete respectively. Similarly, the member function construct() uses the global placement new. Why not allow for any user-defined global or class-specific overloads? Why is alignment set to hard-coded 16 bytes instead of std::alignment_of<T> ? Why do the constructors and max_size have a throw() exception specification? Isn't

Questions about Hinnant&#39;s stack allocator

与世无争的帅哥 提交于 2019-11-26 10:23:30
问题 I\'ve been using Howard Hinnant\'s stack allocator and it works like a charm, but some details of the implementation are a little unclear to me. Why are global operators new and delete used? The allocate() and deallocate() member functions use ::operator new and ::operator delete respectively. Similarly, the member function construct() uses the global placement new. Why not allow for any user-defined global or class-specific overloads? Why is alignment set to hard-coded 16 bytes instead of