![](/img/trans.png)
[英]Noexcept promise on derived class constructor: can that be used without promising noexcept on base constructor?
[英]How can I say “noexcept if execution of protected base constructor is noexcept”?
我們有這種情況,並想知道解決它的最佳方法
template<typename T>
struct A : T {
A(T &&t) noexcept(noexcept(T(std::move(t))))
:T(std::move(t))
{ }
};
遺憾的是,這無法編譯,因為T的移動構造函數受到保護,我們只允許在*this
的構造函數初始化列表中調用它。 有什么辦法使這項工作或甚至有一個標准的方法呢?
您正在尋找noexcept(std::is_nothrow_move_constructible<T>::value)
: http noexcept(std::is_nothrow_move_constructible<T>::value)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.