Skip to content

Commit

Permalink
iox-#1969 Enable implicit conversion of 'ValueType' to 'expected' wit…
Browse files Browse the repository at this point in the history
…h success value
  • Loading branch information
elBoberido committed Apr 11, 2023
1 parent 7f9a29b commit 97acb2c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions iceoryx_hoofs/vocabulary/include/iox/detail/expected.inl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ inline expected<ValueType, ErrorType>::expected(expected<ValueType, ErrorType>&&
{
}

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>::expected(ValueType&& value) noexcept
: m_store(in_place_index<VALUE_INDEX>(), std::move(value))
{
}

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>::expected(const ValueType& value) noexcept
: m_store(in_place_index<VALUE_INDEX>(), value)
{
}

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>&
expected<ValueType, ErrorType>::operator=(expected<ValueType, ErrorType>&& rhs) noexcept
Expand Down
13 changes: 13 additions & 0 deletions iceoryx_hoofs/vocabulary/include/iox/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ class IOX_NO_DISCARD expected<ValueType, ErrorType> final
/// ValueType or ErrorType to correctly invalidate the stored object
expected(expected&& rhs) noexcept;

/// @brief Creates an 'expected' by forwarding value to the constructor of
/// 'ValueType'. This 'expected' has a success value.
/// @param[in] value rvalue of type 'ValueType' which will be moved into the 'expected'
// AXIVION DISABLE STYLE AutosarC++19_03-A12.1.4 : the usage of 'ValueType' shall be transparent when used with an 'expected'
// NOLINTNEXTLINE(hicpp-explicit-conversions)
expected(ValueType&& value) noexcept;

/// @brief Creates an 'expected' by using the copy constructor of 'ValueType'.
/// @param[in] value lvalue of type 'ValueType' which will be copy constructed into the 'expected'
// AXIVION DISABLE STYLE AutosarC++19_03-A12.1.4 : the usage of 'ValueType' shall be transparent when used with an 'expected'
// NOLINTNEXTLINE(hicpp-explicit-conversions)
expected(const ValueType& value) noexcept;

/// @brief calls the destructor of the success value or error value - depending on what
/// is stored in the expected
~expected() noexcept = default;
Expand Down

0 comments on commit 97acb2c

Please sign in to comment.