
void f(const T&& val) 这样的常量右值,虽然编译能通过,但总觉得语义上怪怪的,就想问问这种写法到底有没有意义,还是只是单纯的因为 reference collapsing 所以才保留这种写法? (日常水,轻喷。。
1 dangyuluo 2020-09-15 01:15:23 +08:00 The semantics of getting a const rvalue reference (and not for =delete) is for saying: 1. we do not support the operation for lvalues! 2. even though, we still copy, because we can't move the passed resource, or because there is no actual meaning for "moving" it. 真纠结 |
3 Wirbelwind 2020-09-15 19:15:15 +08:00 没什么意义,有时候可以阻止重载 |
4 by73 OP @dangyuluo 顺着你这个引用我找到了稍微有点意义的例子: int* const ptr = new int(9); auto p = std::unique_ptr<int> { std::move(ptr) }; 来源: https://stackoverflow.com/a/60587511 只能勉强接受这个解释了,虽然还是有点理解不能 |
5 by73 OP @amosasas 还是不纠结了,似乎意义不大。。只是凑巧在 folly::futures 里的测试用例看到这个东西,有点好奇 |
6 Sinksky 2020-10-18 00:25:01 +08:00 |