Reputation: 2998
Here is my function template:
template <typename T>
void f(vector<T> &a) noexcept(noexcept( /* ??? */ ))
I want to specify this function will not throw an exception given that the assignment operator =
of T
has noexcept
specification. Is there a way to do this?
Upvotes: 1
Views: 89
Reputation: 3082
You can do that with this:
template<typename T>
void f(std::vector<T>& a) noexcept(std::is_nothrow_copy_assignable<T>::value)
{...}
It places a condition on the noexcept
if copy-assigning T
values is itself declared noexcept
. You can further this into also taking account move-assigning T
.
Upvotes: 2