c++ - Herb Sutter 的 CppCon Perfect Forwarding 幻灯片

标签 c++ c++11 perfect-forwarding

我无法理解有关 Herb Sutter 在他的演示文稿中建议的完美转发选项的几点 "Back to the Basics! Essentials of Modern C++ Style" (@1:15:00) 在 CppCon 2014。 三张相关幻灯片 ( here are the slides online ) 如下: enter image description here enter image description here enter image description here

我认为在选项 #4 中,如果 String 的衰减类型与 std::string 相同并且与规定的没有不同,则应启用模板化成员函数在幻灯片上(否则选项 #2 和 #4 将不等价,并且没有接受非 std::string 右值的 std::string 赋值运算符) . 但除此之外,我不明白

  • 除了右值和之外,选项 #4 还可以窃取什么
  • 为什么,如第三张幻灯片的基准测试所示,选项 #4 比 #2 快得多(尤其是在最后一张基准测试中)。他们不应该做同样的事情吗?

最佳答案

幻灯片有错误,应该是std::enable_if<std::is_same<... , 事实上,在演讲中实际显示的幻灯片中没有错误,你可以看到它 at 1:16:58 :

enter image description here

是的,正如@dyp 指出的那样,std::enable_if_t<std::is_convertible<String, std::string>::value>>更有意义。

关于c++ - Herb Sutter 的 CppCon Perfect Forwarding 幻灯片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29590883/

相关文章:

c++ - 如何在 Cygwin 文件结构中正确放置非默认 C++ 包

c++ - 当 Derived 仅添加方法时,将 Base 指针强制转换为 Derived 指针的有效性

c++ - 带有 C++ 组的 VS 2012 include/lib

c++ - 如何从模板别名切换到 typedef?

c++ - C++ IPC通讯

c++ - STL复制功能的实现?

c++ - 是否可以在不使用 decltype 的情况下推断先前定义的外部变量的类型

c++ - std::apply forward parameters 如何在没有显式 std::forward 的情况下应用?

c++ - 链接器错误( undefined reference )与 `static constexpr const char*` 和完美转发

c++ - 完美转发使用结构化绑定(bind)声明的变量