C
Cory Nelson
I downloaded GCC 4.3 to try and bring myself up to speed on C++0x
stuff, and have run across a question. Suppose you have a class like
this:
struct foo {
foo(const bar &b) : m_b(b) {}
bar m_b;
};
I want to make m_b construct as efficiently as possible, so I also
give foo an rvalue constructor with move semantics:
struct foo {
foo(const bar &b) : m_b(b) {}
foo(bar &&b) : m_b(std::move(b)) {}
bar m_b;
};
Which is not a big deal for a trivial example, but could mean a lot of
code duplication on something more complex with a number of
parameters.
I don't really care what type of reference b is, I just want to send
it right to m_b's constructor implementing move semantics when
possible. Is there an easy solution to this that I'm not seeing?
stuff, and have run across a question. Suppose you have a class like
this:
struct foo {
foo(const bar &b) : m_b(b) {}
bar m_b;
};
I want to make m_b construct as efficiently as possible, so I also
give foo an rvalue constructor with move semantics:
struct foo {
foo(const bar &b) : m_b(b) {}
foo(bar &&b) : m_b(std::move(b)) {}
bar m_b;
};
Which is not a big deal for a trivial example, but could mean a lot of
code duplication on something more complex with a number of
parameters.
I don't really care what type of reference b is, I just want to send
it right to m_b's constructor implementing move semantics when
possible. Is there an easy solution to this that I'm not seeing?