1

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?

Milo Lu
  • 3,176
  • 3
  • 35
  • 46

2 Answers2

2
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.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
2

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&).

Richard Hodges
  • 68,278
  • 7
  • 90
  • 142