Reputation: 5856
The use of noexcept
was pretty clear to me, as the modern optimized way of marking functions with the no throw exception guarantee
struct A {
A() noexcept;
};
In item 14 of effective modern c++ I ecountered the following syntax, referred to as conditionally noexcept
template<class T, size_t N>
void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
The way I get it, is that noexcept
can introduce a truth value context, but then again how can another noexcept be an argument ?
Could someone elaborate on the syntax and semantics of this use of noexcept
?
Upvotes: 5
Views: 848
Reputation: 16777
The keyword noexcept
can be used in two contexts :
noexcept
operator which takes an expression as an argument and returns a bool
indicating whether or not the expression is non-throwing.noexcept
specifier which is used to specify whether a function throws or not. This form optionally takes one bool
constant expression which determines whether the function is noexcept
or not.In the code you have pasted,
noexcept ( noexcept(swap(*a, *b)))
^^^^^^^^ ^^^^^^^^
specifier operator
Upvotes: 5
Reputation: 218098
With:
template<class T, size_t N>
void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
(1) (2)
Upvotes: 10