Python
Java
PHP
IOS
Android
Nodejs
JavaScript
Html5
Windows
Ubuntu
Linux
Qsort 在 C++ 中不适用于哪些类型?
std sort通过使用交换元素std swap 它又使用复制构造函数和赋值运算符 保证您在交换值时获得正确的语义 qsort通过简单地交换元素的底层位来交换元素 忽略与要交换的类型相关的任何语义 虽然qsort尽管不了解您正在排序的类型的
c
Sorting
genericprogramming
qsort
movesemantics
移动 std::vector 时是否需要保留容量?
考虑以下代码 std vector vec vec reserve 500 size t cap vec capacity std vector newVec std move vec assert cap newVec capacity
c
C11
stdvector
languagelawyer
movesemantics
警告:X 的默认移动赋值运算符将多次移动分配虚拟基类 Y
在 C 11 下测试库时 我在 Clang 下收到警告 我以前从未遇到过这个警告 并且搜索并没有提供太多的阅读和研究方式 该警告如下所示 它似乎与多重继承和公共基类有关 但我不清楚触发警告的细节或我应该采取什么措施来解决它 我的第一个问题是
c
C11
multipleinheritance
movesemantics
当变量在初始值设定项列表中使用时,为什么 C++ 不知道在返回中执行隐式移动?
考虑this https godbolt org z 7aKq7v code include
c
movesemantics
C20
C++11 移动语义是在做一些新的事情,还是只是让语义更清晰?
我基本上想弄清楚 整个 移动语义 概念是全新的 还是只是使现有代码更易于实现 我总是对减少调用复制 构造函数的次数感兴趣 但我通常使用引用 可能还有 const 来传递对象 并确保我始终使用初始化列表 考虑到这一点 并查看了整个丑陋的 语法
c
performance
Optimization
C11
movesemantics
在基于范围的 for 循环中使用转发引用有什么优点?
const auto 如果我想执行只读操作就足够了 然而 我却遇到了 for auto e v v is non const 最近几次 这让我想知道 与其他方法相比 在某些模糊的极端情况下 使用转发引用是否可能会带来一些性能优势 auto
c
performance
forloop
C11
movesemantics
return 语句何时需要显式移动?
In a 对另一个问题的评论 https stackoverflow com q 17473753 321013乔纳森 韦克利回应我的声明 您永远不需要显式移动局部变量函数返回 价值 这是隐式的移动 gt 永远不要说永远 如果局部变量 您需
c
C11
Return
implicitconversion
movesemantics
std::forward 是否有带有纯右值的用例?
最常见的用法是std forward是为了完善转发转发 通用 参考 例如 template
c
C11
movesemantics
rvaluereference
std::move_if_no except 仍然移动抛出仅移动类型的基本原理?
move if noexcept http en cppreference com w cpp utility move if noexcept will 返回一个右值 促进移动 如果移动构造函数是noexcept 或者如果没有复制构造函数
c
movesemantics
noexcept
为什么 `std::stringstream::stringstream(std::string&&)` 不存在?
我希望stringstream有一个构造函数从 a 中窃取其初始内容string STL中一般不存在这种跨物种的 移动构造函数 吗 如果没有 为什么不呢 有历史 令人失望 但也有一个看起来光明的未来 当移动语义进入 C 11 时 它是巨大的
c
C17
movesemantics
stringstream
rvaluereference
复制和移动习语?
通过使用复制和交换 https stackoverflow com questions 3279543 what is the copy and swap idiom rq 1我们可以轻松地实现具有强大异常安全性的复制赋值 T operat
c
C11
movesemantics
copyandswap
何时应在函数返回值上使用 std::move? [复制]
这个问题在这里已经有答案了 在这种情况下 struct Foo Foo meh return std move Foo 我很确定此举是不必要的 因为新创建的Foo将是一个 x 值 但在这样的情况下该怎么办呢 struct Foo Foo m
c
C11
movesemantics
为什么我要 std::move std::shared_ptr?
我一直在寻找铿锵源码 https clang llvm org doxygen CompilerInstance 8cpp source html l00069我发现了这个片段 void CompilerInstance setInvoca
c
C11
sharedptr
smartpointers
movesemantics
C++11 - 2 个向量之间的 emplace_back 不起作用
我试图调整一些代码并将内容从一个向量移动到另一个向量emplace back include
c
vector
C11
movesemantics
为什么局部变量的常量性会抑制返回值的移动语义?
struct STest public boost noncopyable STest STest test m n std move test m n explicit STest int n m n n int m n STest Fu
C11
Return
constants
movesemantics
rvaluereference
重载算术中的移动语义和右值引用传递
我正在用 C 编写一个小型数值分析库 我一直在尝试使用最新的 C 11 功能 包括移动语义 来实现 我理解以下帖子中的讨论和最佳答案 C 11 右值和移动语义混淆 return 语句 https stackoverflow com ques
c
C11
rvaluereference
movesemantics
复制/移动省略与显式删除的复制/移动构造函数
我想知道复制 移动省略何时适用 或允许适用 显式deleted 复制 移动构造函数和非deleted 复制 移动构造函数 具体如下 可以明确地deleted 复制 ctor 或移动 ctor 被删除 是否尝试从另一个相同类型的对象或临时对象
c
constructor
movesemantics
deleteoperator
copyelision
从自身内部替换 std::function (通过移动赋值给 *this?)
可以换一个吗std function从自身内部与另一个std function 以下代码无法编译 include
c
C11
movesemantics
stdfunction
thispointer
移动 lambda:一旦移动捕获了仅移动类型,如何使用 lambda? [复制]
这个问题在这里已经有答案了 这个答案 https stackoverflow com a 20669290 1858225解释了如何在 C 14 中移动捕获 lambda 中的变量 但是一旦你移动捕获了一个不可复制的对象 例如std uni
c
Lambda
c14
movesemantics
stdmove
默认的 Move 构造函数是否定义为 noexcept?
看起来向量会在重新分配时决定是否移动或复制元素之前检查移动构造函数是否标记为 noexcept 默认的移动构造函数是否定义为 noexcept 我看到了以下文档 但没有具体说明这一点 http en cppreference com w c
c
C11
constructor
movesemantics
«
1
2
3
4
5
6
7
»