相关疑难解决方法(0)

std :: make_tuple不会引用

我一直在尝试std::tuple与参考文献结合:

#include <iostream>
#include <tuple>

int main() {
  int a,b;
  std::tuple<int&,int&> test(a,b);
  std::get<0>(test) = 1;
  std::get<1>(test) = 2;
  std::cout << a << ":" << b << std::endl;

  // doesn't make ref, not expected
  auto test2 = std::make_tuple(a,b);
  std::get<0>(test2) = -1;
  std::get<1>(test2) = -2;
  std::cout << a << ":" << b << std::endl;

  int &ar=a;
  int &br=b;
  // why does this not make a tuple of int& references? can we force it to notice?
  auto test3 = std::make_tuple(ar,br);
  std::get<0>(test3) …
Run Code Online (Sandbox Code Playgroud)

c++ tuples reference c++11

36
推荐指数
2
解决办法
1万
查看次数

要返回std :: move(x)还是不?

std::vector<double> foo ()
{
    std::vector<double> t;
    ...

    return t;
}
Run Code Online (Sandbox Code Playgroud)

std::vector<double> foo ()
{
    std::vector<double> t;
    ...

    return std::move (t);
}
Run Code Online (Sandbox Code Playgroud)

相当于?

更确切地说,return x总是相当于return std::move (x)

c++ move-semantics

12
推荐指数
1
解决办法
496
查看次数

标签 统计

c++ ×2

c++11 ×1

move-semantics ×1

reference ×1

tuples ×1