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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.