Commit 40bbf3fd authored by Ben Boeckel's avatar Ben Boeckel
Browse files

Status: offer an `IsSuccess` method

This method makes usage much easier to read than prepending with `!!` or
`static_cast<bool>` to extract a boolean from the structure.
parent b001c54d
......@@ -55,7 +55,10 @@ public:
#endif
/** Return true on "Success", false otherwise. */
explicit operator bool() const { return this->Kind_ == Kind::Success; }
bool IsSuccess() const { return this->Kind_ == Kind::Success; }
/** Return true on "Success", false otherwise. */
explicit operator bool() const { return this->IsSuccess(); }
/** Return the kind of status. */
Kind GetKind() const { return this->Kind_; }
......
......@@ -31,6 +31,10 @@ int testStatus(int, char* [])
std::cerr << "Status Success constructor does not produce Success\n";
res = false;
}
if (!status.IsSuccess()) {
std::cerr << "Status Success gives false IsSuccess\n";
res = false;
}
if (!status) {
std::cerr << "Status Success kind is not true\n";
res = false;
......@@ -55,6 +59,10 @@ int testStatus(int, char* [])
std::cerr << "Status POSIX constructor does not produce POSIX\n";
res = false;
}
if (status.IsSuccess()) {
std::cerr << "Status POSIX gives true IsSuccess\n";
res = false;
}
if (status) {
std::cerr << "Status POSIX kind is not false\n";
res = false;
......@@ -87,6 +95,10 @@ int testStatus(int, char* [])
std::cerr << "Status Windows constructor does not produce Windows\n";
res = false;
}
if (status.IsSuccess()) {
std::cerr << "Status Windows gives true IsSuccess\n";
res = false;
}
if (status) {
std::cerr << "Status Windows kind is not false\n";
res = false;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment