std::basic_stacktrace<Allocator>::operator=
来自 cppreference.cn
< cpp | utility | basic stacktrace
basic_stacktrace& operator=( const basic_stacktrace& other ); |
(1) | (自 C++23 起) |
basic_stacktrace& operator=( basic_stacktrace&& other ) noexcept(/* 见下文 */); |
(2) | (自 C++23 起) |
替换 basic_stacktrace
的内容。
1) 复制赋值运算符。用 other 内容的副本替换内容。
如果 std::allocator_traits<allocator_type>::propagate_on_container_copy_assignment::value 为 true,则 *this 的分配器将被 other 的分配器的副本替换。 如果赋值后 *this 的分配器与其旧值比较不相等,则旧分配器用于释放内存,然后新分配器用于在复制条目之前分配内存。 否则,*this 拥有的内存可以在可能的情况下重复使用。
2) 移动赋值运算符。使用移动语义将 other 的内容替换为内容 (即,other 中的数据从 other 移动到 *this)。 之后,other 处于有效但不明确的状态。
如果 std::allocator_traits<allocator_type>::propagate_on_container_move_assignment::value 为 true,则 *this 的分配器将被 other 的分配器的副本替换。 如果为 false 且 *this 和 other 的分配器比较不相等,则 *this 无法取得 other 拥有的内存的所有权,并且必须单独分配每个条目,并根据需要使用其自身的分配器分配额外的内存。
在任何情况下,最初属于 *this 的堆栈回溯条目可能会被销毁或被逐元素赋值替换。
如果实现加强异常规范,则 *this 可能会在分配失败时设置为空。
目录 |
[编辑] 参数
other | - | 另一个 basic_stacktrace 用作源 |
[编辑] 返回值
*this
[编辑] 复杂度
1) 与 *this 和 other 的大小成线性关系。
2) 与 *this 的大小成线性关系,除非分配器比较不相等且不传播,在这种情况下,与 *this 和 other 的大小成线性关系。
[编辑] 异常
1) 可能会抛出实现定义的异常。
2)
noexcept 规范:
noexcept(std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value
|| std::allocator_traits<Allocator>::is_always_equal::value)
|| std::allocator_traits<Allocator>::is_always_equal::value)
[编辑] 注解
在容器移动赋值(重载 (2))之后,除非元素级移动赋值因不兼容的分配器而强制执行,否则对 other
的引用、指针和迭代器(末尾迭代器除外)仍然有效,但引用现在位于 *this 中的元素。 当前标准通过 [container.reqmts]/67 中的一揽子声明做出此保证,并且正在通过 LWG issue 2321 考虑更直接的保证。
[编辑] 示例
本节不完整 原因:没有示例 |
[编辑] 参见
创建新的 basic_stacktrace (公共成员函数) |