#include <iostream>
#define ERROR_VALUES ERROR_VALUE(NO_ERROR, 0, "Everything is fine")\
ERROR_VALUE(FILE_NOT_FOUND, 1, "File is not found")\
ERROR_VALUE(LABEL_UNINITIALISED, 2, "A component tried to the label before it was initialised")\
ERROR_VALUE(UKNOWN_ERROR, -1, "Uh oh")
enum class Error
{
#define ERROR_VALUE(NAME,VALUE,DESCR) NAME=VALUE,
ERROR_VALUES
#undef ERROR_VALUE
} ;
inline std:: ostream & operator<< ( std:: ostream & os, Error err)
{
int errVal = static_cast < int > ( err) ;
switch ( err)
{
#ifndef PRODUCTION_BUILD // Don't print out names in production builds
#define ERROR_VALUE(NAME,VALUE,DESCR) case Error::NAME: return os << "[" #VALUE "]" #NAME <<"; " << DESCR;
ERROR_VALUES
#undef ERROR_VALUE
#endif
default :
return os << errVal;
}
}
int main( ) {
std:: cout << "Error: " << Error:: NO_ERROR << std:: endl ;
std:: cout << "Error: " << Error:: FILE_NOT_FOUND << std:: endl ;
std:: cout << "Error: " << Error:: LABEL_UNINITIALISED << std:: endl ;
std:: cout << "Error: " << Error:: UKNOWN_ERROR << std:: endl ;
return 0 ;
}
ICAgICNpbmNsdWRlIDxpb3N0cmVhbT4KICAgICAgICAjZGVmaW5lIEVSUk9SX1ZBTFVFUyBFUlJPUl9WQUxVRShOT19FUlJPUiwgMCwgIkV2ZXJ5dGhpbmcgaXMgZmluZSIpXAogICAgRVJST1JfVkFMVUUoRklMRV9OT1RfRk9VTkQsIDEsICJGaWxlIGlzIG5vdCBmb3VuZCIpXAogICAgRVJST1JfVkFMVUUoTEFCRUxfVU5JTklUSUFMSVNFRCwgMiwgIkEgY29tcG9uZW50IHRyaWVkIHRvIHRoZSBsYWJlbCBiZWZvcmUgaXQgd2FzIGluaXRpYWxpc2VkIilcCiAgICBFUlJPUl9WQUxVRShVS05PV05fRVJST1IsIC0xLCAiVWggb2giKQogICAgCiAgICBlbnVtIGNsYXNzIEVycm9yCiAgICB7CiAgICAjZGVmaW5lIEVSUk9SX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