Error codes and error conditions

Notice that FinickyFS::Error is not implicitly convertible to std::error_code; in the last example, we used the syntax make_error_code(FinickyFS::Error::forbidden_word) to construct our initial error_code object. We can make FinickyFS::Error more convenient for the programmer if we tell <system_error> to enable implicit conversions from FinickyFS::Error to std::error_code, as follows:

    namespace std {    template<>    struct is_error_code_enum<::FinickyFS::Error> : true_type {};    } // namespace std

Be careful when reopening namespace std--remember that you must be outside any other namespace when you do it! Otherwise, you'll be creating a nested namespace such as namespace FinickyFS::std. In this particular case, ...

Get Mastering the C++17 STL now with O’Reilly online learning.

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