6
我想为某个类型实现移动构造函数(无拷贝构造函数),该构造函数需要是boost::unordered_map
中的值类型。我们称这种类型为Composite
。移动构造函数和初始化列表
Composite
具有以下特征:
struct Base
{
Base(..stuff, no default ctor) : initialization list {}
Base(Base&& other) : initialization list {}
}
struct Composite
{
Base member;
Composite(..stuff, no default ctor) : member(...) {}
Composite(Composite&& other) : member(other.member) {} // <---- I want to make sure this invokes the move ctor of Base
}
我想写这使boost::unordered_map< Key , Composite >
不需要拷贝构造函数,并且只使用移动的构造。如果可能,我不想在Composite
的移动构造函数的初始化列表中使用Base
的拷贝构造函数。
这可能吗?
+1为了更好地使用相对较新的术语* universal reference *。 – mavam
@MatthiasVallentin:这个词是由Scott Meyers当场作出的。标准委员会现在更喜欢“转发参考”这个术语。 –
现在我们差不多两年了,很高兴看到社区已经在一个稳定的时期内融合了。 – mavam