Milo Lu
Milo Lu

Reputation: 3356

How to evaluate the result of the noexcept() operator

For example,

template<class T,size_t N>
void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a,*b)));

Under what condition will the function can, or cannot, throw an exception?

Upvotes: 1

Views: 74

Answers (2)

Karoly Horvath
Karoly Horvath

Reputation: 96258

noexcept(noexcept(swap(*a,*b)))

The outer one is the noexcept specifier, the inner one is the noexcept operator.

It's noexcept, if swap for Ts is noexcept.

That it's, it can only throw if that swap can throw.

Upvotes: 2

Richard Hodges
Richard Hodges

Reputation: 69854

quick explanation:

the inner noexcept returns true if the function swap(T&, T&) is marked noexcept.

the outer noexcept marks this function as noexcept if the inner noexcept returns true.

Therefore, this function copies the noexcept semantics of swap(T&, T&).

Upvotes: 2

Related Questions