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