具有可以引发的移动操作的仅移动类的示例是什么?
What's an example of a move-only class with a move operation that can throw?
std::move_if_noexcept
定义如下(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)
用普通的英语,如果x
的移动构造器不投掷,或者x
不复制可构造构造,则move_if_noexcept(x)
将x
施放到RVALUE。这使我想知道是否有任何常见类型不可复制,但其移动构造函数可能会抛出。
在标准库中,我已经检查了不可复制的类型unique_ptr
,future
,promise
,各种静音类型,unique_lock
,packaged_task
和CC_11,除非我误读了标准,否则他们都声明了他们的移动操作noexcept
。
标准库(C 11或C 14)或常用的第三方库(例如Boost)中是否存在仅移动类型的类型?
fstream类是移动构造函数未声明为noexcept和复制构造函数的示例:http://en.cppreference.com/w/cpp/io/basic_ofstream/basic_ofstream/basic_ofstream
/div>相关文章:
- 在C++中使用移动语义的正确方法是什么?
- 是什么解释了这个片段中如此多的移动和破坏
- 具有可以引发的移动操作的仅移动类的示例是什么?
- 移动和键比较在 C++ 中是什么意思
- 移动构造函数相对于复制构造函数的优势是什么?复制构造函数使用bool来表示是复制还是移动
- 对于默认定义的移动构造函数,noexcept的规则是什么
- 相对于其数据在特定方向上移动的有效方法是什么
- ZeroMQ 的替代方案是什么,用于移动协议缓冲区有效负载
- 移动平台的预处理器定义是什么?
- 移动构造函数的后置条件是什么
- 消除默认/删除移动/复制语义中涉及的样板的好方法是什么
- 在 C++11 中编写复制/移动/运算符 = 三重奏的"correct"方法是什么?
- 一次移动多个未签名字符以便它们从一个字符流向另一个字符的最快方法是什么?
- 编译器生成移动构造函数的行为是什么?
- 将视频帧数据移动到GPU的最有效方法是什么?
- 在MVP层之间移动数据的众所周知的方法是什么?
- 移动语义 - 它的全部内容是什么?
- 错误到底是什么,对于错误地调用可移动和不可复制成员的复制构造函数有什么解决方法
- 编译器用来决定移动操作是否安全的标准是什么
- 使用移动成本低但复制量大的对象初始化容器的首选方法是什么