Alf P. Steinbach /Usenet wrote:
* Sousuke, on 24.06.2010 17:23:
The optimizations that rvalue references make possible are nice,
but I'm having one problem with them (rvalue refs): they sometimes
lead to too much verbosity.
When defining a constructor or a setter, you usually take a const
T& and assign it to one of the class's members. In C++0x, you can
additionally define an overload that takes a T&&:
class OneString
{
public:
OneString(const string& s) : m_s(s)
{
}
OneString(string&& s) : m_s(move(s))
{
}
private:
string m_s;
};
One additional overload is not too much verbosity, but see the two-
argument case:
class TwoStrings
{
public:
TwoStrings(const string& s1, const string& s2) : m_s1(s1),
m_s2(s2)
{
}
TwoStrings(string&& s1, const string& s2) : m_s1(move(s1)),
m_s2(s2)
{
}
TwoStrings(const string& s1, string&& s2) : m_s1(s1),
m_s2(move(s2))
{
}
TwoStrings(string&& s1, string&& s2) : m_s1(move(s1)),
m_s2(move(s2))
{
}
private:
string m_s1;
string m_s2;
};
I don't even know how many overloads would there be for 3 arguments
(27 maybe?).
Is there a way to avoid this verbosity?
With the disclaimer that I haven't actually used C++0x rvalue
references, why do you want the ordinary reference overloads? I
thought much of the point was that an rvalue reference could deal
with both cases. Isn't it so?
No, it didn't turn out that way in the end. :-(
will not bind to rvalue references.