Python
Java
PHP
IOS
Android
Nodejs
JavaScript
Html5
Windows
Ubuntu
Linux
为什么 Rust 不允许在一种类型上复制和删除特征?
From the book https doc rust lang org book 2018 edition ch04 01 what is ownership html stack only data copy Rust 不允许我们用C
Rust
traits
movesemantics
ownership
与右值交换
假设我想要swap它适用于右值 并且不想为右值 左值引用的所有组合编写 4 个版本 右值 右值版本有点毫无意义 但也无害 我想出了这个 template
c
SWAP
movesemantics
rvaluereference
为什么要重新分配向量副本而不是移动元素? [复制]
这个问题在这里已经有答案了 可能的重复 当向量增长时如何强制移动语义 https stackoverflow com questions 8001823 how to enforce move semantics when a vector
c
C11
stdvector
movesemantics
我如何从 Rust 的 Vec 中获取项目?
我正在寻找一种方法consumes a Vec并返回一个元素 无需恢复的开销Vec的不变量的方式remove and swap remove do fn take
vector
Collections
Rust
movesemantics
转换为“const Y”不适用于 clang 上的“R&&”
以下代码可以正常编译g GCC 4 7 1 20120721 但 最近构建失败clang version 3 2 trunk struct Y struct X operator const Y const return Y void f
c
C11
g
Clang
movesemantics
调用左值引用构造函数而不是右值引用构造函数
有这样的代码 include
c
C11
movesemantics
rvaluereference
转换运算符的移动语义
可移动转换运算符的语法是什么 我有一个可以包裹的包装纸obj 其中有一个obj转换运算符 class wrap public operator obj private obj data 我怎样才能知道是否data 应该复制还是移动 其语法如
c
C11
movesemantics
我应该将局部变量设置为常量还是可移动?
我对本地范围内的任何对象的默认行为是使其const E g auto const cake bake cake arguments 我尝试尽可能少地使用非功能代码 因为这可以提高可读性 并为编译器提供一些优化机会 因此 在类型系统中也反映这
c
C17
movesemantics
constcorrectness
std::vector
当 Foo 的某些成员是引用时
只要有可能 我通常更喜欢使用引用而不是指针 在我看来 它使语法更清晰 在这种情况下 我有一堂课 class Foo public Foo Bar bar bar bar private Bar bar operator 对于这样的类 编译器
c
C11
stdvector
movesemantics
默认移动构造函数/赋值和删除的复制构造函数/赋值
根据标准 如果类 X 的定义没有显式声明移动构造函数 则当且仅当 X 没有用户声明的复制构造函数 X 没有用户声明的复制赋值运算符 X 没有用户声明的移动赋值运算符 并且 X 没有用户声明的析构函数 现在以下无法编译 include
c
movesemantics
deletedfunctions
如何判断一个类型是否真正可移动构造
以这段代码为例 include
c
STL
movesemantics
typetraits
移动语义对于 Rust 中的引用透明性意味着什么?
我正在尝试弄清楚移动语义如何影响引用透明度 参考透明度 https stackoverflow com q 210835 5986907 RT 允许我们用结果替换任何表达式 而不改变程序的含义 释义自 例如 我可以替换1 1我的程序中的任何
functionalprogramming
Rust
movesemantics
referentialtransparency
为什么要有移动语义?
首先我要说的是 我已经阅读了有关移动语义的许多问题中的一些 这个问题不是关于如何使用移动语义 而是问它的目的是什么 如果我没有记错的话 我不明白为什么需要移动语义 背景 我正在实现一个重磅课程 就这个问题而言 它看起来像这样 class B
c
C11
movesemantics
为什么可以在没有 std::move 的情况下返回 std::unique_ptr ?
unique ptr
c
C11
uniqueptr
movesemantics
“由于在生成器中使用而发生移动”错误是什么意思?
我遇到了关于生成器的问题 use tokio runtime Runtime use tokio task JoinHandle use std sync Arc pub fn run f Box
Rust
smartpointers
movesemantics
通过多次传递输入参数实现完美转发
考虑以下函数accept采用 通用引用 类型T并将其转发给parse
c
C11
movesemantics
rvaluereference
perfectforwarding
从常量引用中移动构造
我遇到以下情况 需要从 t1 中移动构造 t2 不幸的是 这是不可能的 我想是违反常量的 从 foo 的调用者那里透明地处理这个问题的正确方法是什么 即不需要传值和显式 std move struct T T default T defau
c
C11
move
movesemantics
应该使用 unique_ptr 来更轻松地实现“移动”语义吗?
Edit made Foo and Bar稍微不那么琐碎 直接替换为shared ptr lt gt 更加困难 Should unique ptr lt gt 用作实现移动语义的更简单方法 对于像这样的课程 class Foo int m
c
C11
movesemantics
uniqueptr
移动构造函数和初始化列表
我想为需要成为值类型的特定类型实现移动构造函数 无复制构造函数 boost unordered map 我们称这种类型为Composite Composite有以下签名 struct Base Base stuff no default c
c
C11
initialization
unorderedmap
movesemantics
复制赋值运算符应该通过常量引用传递还是通过值传递?
在 C 11 之前 复制赋值运算符始终应通过 const 引用传递 如下所示 template
c
C11
movesemantics
assignmentoperator
1
2
3
4
5
6
7
»