函数dual to std :: move? [英] Function dual to std::move?

查看:176
本文介绍了函数dual to std :: move?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我有一个类只有一个构造函数:

Let's assume I have a class with only one constructor:

class T {
 public:
  T(BigClass&& big) : big(std::move(big)) {}
  ...

  SomeBigClass
};

在大多数地方,构造函数在临时表上被调用,但在一个地方,我需要做一个明确的副本BigClass因为它不是一个临时的,并且将在一个循环中使用多次:

In most places the constructor is called on temporaries but in one place I need to make an explicit copy of BigClass because it is not a temporary and will be used multiple times in a loop:

void foo(const BigClass& big) {
  while (...) {
    T t(std::make_a_copy(big));
    ...
  }
}

在C ++ 11或C ++ 14中的dual到 std :: move 将替换上面的make_a_copy?

Is there any function "dual" to std::move in C++11 or C++14 that would replace make_a_copy above ?

编辑:有些澄清。

推荐答案

$ c> BigClass object?

Why can't you just copy the BigClass object?

void foo(const BigClass& big) {
  while (...) {
    T t{ BigClass(big) };
    ...
  }
}

BigClass ,然后移动到 T

这篇关于函数dual to std :: move?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆