小编ale*_*exc的帖子

在重载函数的函数参数中使用rvalue引用会创建太多组合

想象一下,你有很多重载的方法(在C++ 11之前)看起来像这样:

class MyClass {
public:
   void f(const MyBigType& a, int id);
   void f(const MyBigType& a, string name);
   void f(const MyBigType& a, int b, int c, int d);
   // ...
};
Run Code Online (Sandbox Code Playgroud)

这个函数复制了a(MyBigType),所以我想通过提供一个版本f来移动a而不是复制它来添加优化.

我的问题是,现在f重载次数将重复:

class MyClass {
public:
   void f(const MyBigType& a, int id);
   void f(const MyBigType& a, string name);
   void f(const MyBigType& a, int b, int c, int d);
   // ...
   void f(MyBigType&& a, int id);
   void f(MyBigType&& a, string …
Run Code Online (Sandbox Code Playgroud)

c++ rvalue-reference c++11

19
推荐指数
3
解决办法
1855
查看次数

标签 统计

c++ ×1

c++11 ×1

rvalue-reference ×1