문제

std::move_if_noexcept is defined as follows (C++11 20.2.3/7-8):

template <class T>
typename conditional<!is_nothrow_move_constructible<T>::value
                     && is_copy_constructible<T>::value,
                     const T&,
                     T&&
                    >::typemove_if_noexcept(T& x) noexcept;

Returns: std::move(x)

In plain English, move_if_noexcept(x) casts x to an rvalue if x's move constructor doesn't throw or if x isn't copy constructible. That leads me to wonder if there are any commonly available types that are not copyable, but whose move constructor might throw.

In the Standard Library, I've checked the uncopyable types unique_ptr, future, promise, the various mutex types, unique_lock, condition_variable, and packaged_task, and, unless I'm misreading the standard, they all declare their move operations noexcept.

Is there a move-only type in the Standard Library (C++11 or C++14) or in a commonly-used third party library (e.g., Boost) where the move operations may throw?

도움이 되었습니까?

해결책

fstream classes are examples of move constructor not declared noexcept and copy constructor deleted : http://en.cppreference.com/w/cpp/io/basic_ofstream/basic_ofstream

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top