-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add(Result): add result and update Server()
- Loading branch information
Showing
7 changed files
with
81 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include <iostream> | ||
|
||
template <typename OkType, typename ErrType> | ||
class Result { | ||
public: | ||
static Result Ok(OkType value) { | ||
Result res; | ||
res._is_ok = true; | ||
res._ok_value = value; | ||
return res; | ||
} | ||
|
||
static Result Err(ErrType value) { | ||
Result res; | ||
res._is_ok = false; | ||
res._err_value = value; | ||
return res; | ||
} | ||
|
||
bool is_ok() const { return _is_ok; } | ||
|
||
OkType get_ok_value() const { | ||
if (_is_ok) { | ||
return _ok_value; | ||
} | ||
throw std::runtime_error("Result is not Ok"); | ||
} | ||
|
||
ErrType get_err_value() const { | ||
if (!_is_ok) { | ||
return _err_value; | ||
} | ||
throw std::runtime_error("Result is not Err"); | ||
} | ||
|
||
private: | ||
bool _is_ok; | ||
OkType _ok_value; | ||
ErrType _err_value; | ||
}; |
This file contains 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
This file contains 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
This file contains 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