【发布时间】:2011-11-15 08:25:03
【问题描述】:
目前,我的一个玩具类模板有两个看起来非常相似的构造函数:
optional(const T& x)
{
construct(x);
}
optional(T&& x)
{
construct(std::move(x));
}
我可以将它们组合成一个构造函数模板,还是会以某种方式改变语义?
template<typename U>
optional(U&& x)
{
construct(std::forward<U>(x));
}
【问题讨论】:
-
construct的实际肉是什么? -
@Alf: 丑陋的新东西放置在对齐的存储上 :)
标签: c++ templates c++11 move-semantics perfect-forwarding