Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I say "noexcept if execution of protected base constructor is noexcept"?

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?

like image 378
Johannes Schaub - litb Avatar asked Aug 04 '16 16:08

Johannes Schaub - litb


1 Answers

you are looking for noexcept(std::is_nothrow_move_constructible<T>::value): http://en.cppreference.com/w/cpp/types/is_move_constructible

like image 172
Andrei R. Avatar answered Oct 21 '22 20:10

Andrei R.