Can the noexcept
modifier be applied to a lambda expression? If so, how?
Can noexcept
be made a constraint on a function argument? For example, something like in the following code, where the meaning is that the callback function must be noexcept
?
//probably not valid code - I'm just trying to express the idea
void f_async(std::function<void (int) noexcept> callback) noexcept
{
...
}
This can almost be accomplished with the following code, but I'm wondering if there is a way to use something like the above alternative.
void f_async(std::function<void (int)> callback)
noexcept(callback(std::declval<int>()))
{
...
}
The problem here of course is that f_async
can be noexcept(false)
if the callback is noexcept(false)
- I want to make a stronger statement that f_async
is always noexcept
, meaning it's only callable if you use a noexcept
callback.