Вопрос

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