Kai Wen wrote:
Hello, every one!
I wrote some codes, there seems somgthing wrong with the std::pair.
===========================================================
#include<iostream>
#include<set>
#include<boost/tuple/tuple.hpp>
typedef boost::tuple<std::set<int>, int> first_type;
typedef boost::tuple<std::set<int>, std::pair<int, int>>
second_type;
first_type&& foo1()
{
std::set<int> s{1, 2, 3};
return std::move(boost::make_tuple(s, 22));
}
second_type&& foo2()
{
std::set<int> s{1, 2, 3};
/* Is there something wrong with the pair? */
return std::move(boost::make_tuple(s, std::make_pair(2, 3)));
}
In addition to what Alf said, you probably shouldn't return rvalue
references except in very special cases (like forwarding functions).
Just return the local or temporary by value, and let the receiving
object's move constructor or move assignment pick that up.
When the language has them, that will be true.