Seasons.NET - 戻り値受け取り型templateクラス
#include <iostream> inline bool is_error(int code) { return false; } template <class Head, class... Tail> inline bool is_error(int code, Head head, Tail... tail) { return code == head ? true : is_error(code, tail...); } template <int ...ErrorCode> class error_code { int value_; public: error_code(int value) : value_(value) {} error_code& operator=(int value) { value_ = value; return *this; } int code() const { return value_; } bool fail() const { return is_error(value_, ErrorCode...); } operator bool() const { return fail(); } }; typedef error_code<-1> win32_error; int main() { win32_error err = -1; if (err) { std::cout << "Error : " << err.code() << std::endl; } }