How it works...

The noexcept operator is used to determine whether a function can throw. Let's start with a simple example:

#include <iostream>#include <stdexcept>void foo(){    std::cout << "The answer is: 42\n";}int main(void){    std::cout << std::boolalpha;    std::cout << "could foo throw: " << !noexcept(foo()) << '\n';    return 0;}

This results in the following:

As shown in the preceding example, we defined a foo() function that outputs to stdout. We don't actually execute foo() but, instead, we use the noexcept operator to check to see whether the foo() function could throw. As you can see, the answer is yes; this function can throw. This is because ...

Get Advanced C++ Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.