Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions include/common/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Result {
* - T must have a default constructor
*/
constexpr Result()
noexcept(std::is_nothrow_default_constructible_v<T>)
requires std::default_initializable<T>
= default;

Expand All @@ -47,6 +48,7 @@ class Result {
* - T must be constructible with perfectly forwarded value argument
*/
template<typename U>
noexcept(std::nothrow_constructible_from_v<T, U&&>)
requires std::constructible_from<T, U&&>
constexpr Result(U&& value)
: value(std::forward<U>(value)) {}
Expand All @@ -60,6 +62,7 @@ class Result {
* - T must be default initializable
*/
constexpr Result(E error)
noexcept(std::is_nothrow_default_constructible_v<T>)
requires std::default_initializable<T>
: error(error) {}

Expand All @@ -75,6 +78,7 @@ class Result {
* - T must be constructible with perfectly forwarded value argument
*/
template<typename U>
noexcept(std::nothrow_constructible_from_v<T, U&&>)
requires std::constructible_from<T, U&&>
constexpr Result(E error, U&& value)
: error(error),
Expand All @@ -85,7 +89,7 @@ class Result {
*
* @return T&
*/
constexpr operator T&() & {
constexpr operator T&() & noexcept {
return value;
}

Expand All @@ -94,7 +98,7 @@ class Result {
*
* @return const T&
*/
constexpr operator const T&() const& {
constexpr operator const T&() const& noexcept {
return value;
}

Expand All @@ -103,7 +107,7 @@ class Result {
*
* @return T&&
*/
constexpr operator T&&() && {
constexpr operator T&&() && noexcept {
return std::move(value);
}

Expand All @@ -117,7 +121,7 @@ class Result {
* @return "normal" value
*/
template<typename Self>
constexpr auto get_value(this Self&& self) {
constexpr auto get_value(this Self&& self) noexcept(noexcept(std::forward<Self>(self).value)) {
return std::forward<Self>(self).value;
}

Expand All @@ -127,7 +131,7 @@ class Result {
* @return true an error is contained
* @return false an error is not contained
*/
constexpr bool has_error() {
constexpr bool has_error() const noexcept {
return error.has_value();
}

Expand All @@ -139,12 +143,12 @@ class Result {
* @return true error is contained
* @return false error is not contained
*/
constexpr bool contains(E error) {
constexpr bool contains(E error) const noexcept(noexcept(std::declval<E>() == std::declval<E>())) {
return this->error == error;
}

// prevent ambiguous operator overload resolution
bool operator==(const Result& other) = delete;
};

} // namespace zest
} // namespace zest
Loading