Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1969 Enable default ctors for 'iox::expected'
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed Apr 11, 2023
1 parent fa86dcb commit 7f9a29b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
7 changes: 7 additions & 0 deletions iceoryx_hoofs/vocabulary/include/iox/detail/expected.inl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ inline expected<ValueType, ErrorType>::expected(variant<ValueType, ErrorType>&&
{
}

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>::expected() noexcept
: m_store(in_place_index<VALUE_INDEX>(), ValueType{})
{
static_assert(std::is_default_constructible<ValueType>::value, "'ValueType' must be default constructible!");
}

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>::expected(const success<ValueType>& successValue) noexcept
: m_store(in_place_index<VALUE_INDEX>(), successValue.value)
Expand Down
11 changes: 5 additions & 6 deletions iceoryx_hoofs/vocabulary/include/iox/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,8 @@ template <typename ErrorType>
class IOX_NO_DISCARD expected<ErrorType> final : public FunctionalInterface<expected<ErrorType>, void, ErrorType>
{
public:
/// @brief default ctor is deleted since you have to clearly state if the
/// expected contains a success value or an error value
expected() = delete;
/// @brief default ctor is creates an object which contains an expected value
expected() noexcept = default;

/// @brief the copy constructor calls the copy constructor of the contained success value
/// or the error value - depending on what is stored in the expected
Expand Down Expand Up @@ -263,9 +262,9 @@ class IOX_NO_DISCARD expected<ValueType, ErrorType> final
: public FunctionalInterface<expected<ValueType, ErrorType>, ValueType, ErrorType>
{
public:
/// @brief default ctor is deleted since you have to clearly state if the
/// expected contains a success value or an error value
expected() = delete;
/// @brief default ctor is creates an object which contains an expected value
/// @note the 'ValueType' must be default constructible
expected() noexcept;

/// @brief the copy constructor calls the copy constructor of the contained success value
/// or the error value - depending on what is stored in the expected
Expand Down

0 comments on commit 7f9a29b

Please sign in to comment.