Created
December 4, 2013 15:28
-
-
Save stevenRush/7789496 to your computer and use it in GitHub Desktop.
Some crazy error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <cstdio> | |
#include <cstdarg> | |
template<typename T> | |
class result | |
{ | |
private: | |
T value; | |
public: | |
result(T value) | |
{ | |
this->value = value; | |
} | |
bool success() | |
{ | |
return true; | |
} | |
}; | |
template<> | |
class result<void> | |
{ | |
private: | |
char message[256]; | |
public: | |
result(const char * format, va_list args) | |
{ | |
vsprintf(message, format, args); | |
} | |
bool success() | |
{ | |
return false; | |
} | |
const char * get_message() | |
{ | |
return message; | |
} | |
}; | |
template<typename T> | |
result result_ok(T value) | |
{ | |
return result<T>(value); | |
} | |
result<void> result_fail(const char * format, ...) | |
{ | |
va_list args; | |
va_start(args, format); | |
result<void> result(format, args); | |
va_end(args); | |
return result; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment