Where is std::copy_exception defined?

后端 未结 1 1625
猫巷女王i
猫巷女王i 2021-01-04 02:25

The book C++ Concurrency in Action by Anthony Williams states in 4.2.4 Saving an exception for the future that it is possible to store an exception directl

相关标签:
1条回答
  • 2021-01-04 02:34

    tl;dr: std::copy_exception was renamed to std::make_exception_ptr in <exception> for the final C++11 standard.


    The committee decided that the name copy_exception (probably copied into the standard from boost::copy_exception) was misleading for the following reasons.

    The copy_exception function returns an exception_ptr to a copy of its argument, as if

    template <class E>
    exception_ptr copy_exception(E e) {
        try {
            throw e;
        } catch (...) {
            return current_exception();
        }
    }
    

    When called with an exception_ptr as argument, the function would return another exception_ptr pointing to a copy of the exception_ptr given as argument, instead of pointing to what the exception_ptr argument points to. Because the name copy_exception was misleading for this case, the function was renamed to std::make_exception_ptr for the final C++11 standard. See the C++ Standard Library Defect Report 1130 for details and discussion on this issue.

    The std::make_exception_ptr function is defined in <exception>.

    0 讨论(0)
提交回复
热议问题