Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is std::copy_exception defined?

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 directly without throwing using std::copy_exception. However I seem to be unable to find the standard library header where std::copy_exception is defined. Where can I find it?

like image 271
jotik Avatar asked Jun 15 '16 09:06

jotik


1 Answers

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>.

like image 93
jotik Avatar answered Oct 16 '22 23:10

jotik