我一直在尝试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) 是
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)?