We had this situation and wondered about the best way to fix it
template<typename T>
struct A : T {
A(T &&t) noexcept(noexcept(T(std::move(t))))
:T(std::move(t))
{ }
};
This unfortunately fails to compile because T's move constructor is protected, and we are only allowed to call it in the constructor initialization list for *this
. What are the workarounds to make this work or is there even a standard way for it?
you are looking for noexcept(std::is_nothrow_move_constructible<T>::value)
:
http://en.cppreference.com/w/cpp/types/is_move_constructible
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With