Skip to content

Commit

Permalink
OrcLib: Utils: Result: add ToOptional(Result&)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabienfl-orc committed Jan 26, 2021
1 parent 0825d42 commit 847a254
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/OrcLib/Utils/Result.h
Expand Up @@ -7,6 +7,8 @@
//
#pragma once

#include <optional>

#include <boost/outcome/outcome.hpp>

namespace Orc {
Expand All @@ -26,6 +28,17 @@ const T& operator*(const Result<T>& result)
return result.value();
}

template <typename T>
std::optional<T> ToOptional(const Orc::Result<T>& result)
{
if (result.has_value())
{
return result.value();
}

return {};
}

inline std::error_code SystemError(HRESULT hr)
{
return {hr, std::system_category()};
Expand Down

0 comments on commit 847a254

Please sign in to comment.