Skip to content

Instantly share code, notes, and snippets.

@js2854
Created September 6, 2018 13:17
Show Gist options
  • Save js2854/e1e8006e3d3ab6a4d555766690cf55b8 to your computer and use it in GitHub Desktop.
Save js2854/e1e8006e3d3ab6a4d555766690cf55b8 to your computer and use it in GitHub Desktop.
#ifndef __RESULT_CODE__
#define __RESULT_CODE__
#include <string>
#include <iostream>
using std::string;
using std::ostream;
namespace Result
{
typedef struct T_Result
{
int code;
string msg;
friend ostream& operator<<(ostream& os, const T_Result& res)
{
os << res.code << '(' << res.msg << ')';
return os;
}
} T_Result;
static const T_Result OK = {0, "ok"};
static const T_Result INVALID_PARAMS = {-1, "invalid params"};
};
#endif //__RESULT_CODE__
// usage demo:
// std::cout << Result::OK << std::endl;
// std::cout << Result::INVALID_PARAMS << std::endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment