Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1969 Rename 'success' to 'ok' and 'error' to 'err'
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed May 5, 2023
1 parent 2bda747 commit 8ed505c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
36 changes: 18 additions & 18 deletions iceoryx_hoofs/vocabulary/include/iox/detail/expected.inl
Original file line number Diff line number Diff line change
Expand Up @@ -22,67 +22,67 @@
namespace iox
{
template <typename T, typename>
detail::success<void> ok()
detail::ok<void> ok()
{
return detail::success<void>{};
return detail::ok<void>{};
}

template <typename T, typename>
detail::success<T> ok(const T& value)
detail::ok<T> ok(const T& value)
{
return detail::success<T>{value};
return detail::ok<T>{value};
}

template <typename T, typename, typename>
detail::success<T> ok(T&& value)
detail::ok<T> ok(T&& value)
{
return detail::success<T>{std::forward<T>(value)};
return detail::ok<T>{std::forward<T>(value)};
}

template <typename T, typename... Targs, typename>
detail::success<T> ok(Targs&&... args)
detail::ok<T> ok(Targs&&... args)
{
return detail::success<T>{std::forward<Targs>(args)...};
return detail::ok<T>{std::forward<Targs>(args)...};
}

template <typename T>
detail::error<T> err(const T& value)
detail::err<T> err(const T& value)
{
return detail::error<T>{value};
return detail::err<T>{value};
}

template <typename T, typename>
detail::error<T> err(T&& value)
detail::err<T> err(T&& value)
{
return detail::error<T>{std::forward<T>(value)};
return detail::err<T>{std::forward<T>(value)};
}

template <typename T, typename... Targs>
detail::error<T> err(Targs&&... args)
detail::err<T> err(Targs&&... args)
{
return detail::error<T>{std::forward<Targs>(args)...};
return detail::err<T>{std::forward<Targs>(args)...};
}

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>::expected(const detail::success<ValueType>& successValue) noexcept
inline expected<ValueType, ErrorType>::expected(const detail::ok<ValueType>& successValue) noexcept
: m_store(in_place, successValue.value)
{
}

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>::expected(detail::success<ValueType>&& successValue) noexcept
inline expected<ValueType, ErrorType>::expected(detail::ok<ValueType>&& successValue) noexcept
: m_store(in_place, std::move(successValue.value))
{
}

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>::expected(const detail::error<ErrorType>& errorValue) noexcept
inline expected<ValueType, ErrorType>::expected(const detail::err<ErrorType>& errorValue) noexcept
: m_store(unexpect, errorValue.value)
{
}

template <typename ValueType, typename ErrorType>
inline expected<ValueType, ErrorType>::expected(detail::error<ErrorType>&& errorValue) noexcept
inline expected<ValueType, ErrorType>::expected(detail::err<ErrorType>&& errorValue) noexcept
: m_store(unexpect, std::move(errorValue.value))
{
}
Expand Down
20 changes: 10 additions & 10 deletions iceoryx_hoofs/vocabulary/include/iox/detail/expected_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ namespace detail
{
/// @brief helper struct to create an expected which is signalling success more easily
template <typename T = void>
struct success
struct ok
{
// AXIVION Next Construct AutosarC++19_03-A12.1.5 : This is a false positive since there is no fitting constructor
// available for delegation
explicit success(const T& t) noexcept
explicit ok(const T& t) noexcept
: value(t)
{
}

// AXIVION Next Construct AutosarC++19_03-A18.9.2 : For universal references std::forward must be used
template <typename U = T, typename = enable_if_not_lvalue_referece_t<U>>
explicit success(T&& t) noexcept
explicit ok(T&& t) noexcept
: value(std::forward<T>(t))
{
}

// AXIVION Next Construct AutosarC++19_03-A15.4.2, FaultDetection-NoexceptViolations : Intentional behavior. 'success' is not intended to be used with a type which throws
// AXIVION Next Construct AutosarC++19_03-A15.4.2, FaultDetection-NoexceptViolations : Intentional behavior. 'ok' is not intended to be used with a type which throws
template <typename... Targs>
explicit success(Targs&&... args) noexcept
explicit ok(Targs&&... args) noexcept
: value(std::forward<Targs>(args)...)
{
}
Expand All @@ -75,32 +75,32 @@ struct success

/// @brief helper struct to handle 'void' value type specialization
template <>
struct success<void>
struct ok<void>
{
// dummy value
bool value{true};
};

/// @brief helper struct to create an expected which is signalling an error more easily
template <typename T>
struct error
struct err
{
// AXIVION Next Construct AutosarC++19_03-A12.1.5 : This is a false positive since there is no fitting constructor
// available for delegation
explicit error(const T& t) noexcept
explicit err(const T& t) noexcept
: value(t)
{
}

// AXIVION Next Construct AutosarC++19_03-A18.9.2 : For universal references std::forward must be used
template <typename U = T, typename = enable_if_not_lvalue_referece_t<U>>
explicit error(T&& t) noexcept
explicit err(T&& t) noexcept
: value(std::forward<T>(t))
{
}

template <typename... Targs>
explicit error(Targs&&... args) noexcept
explicit err(Targs&&... args) noexcept
: value(std::forward<Targs>(args)...)
{
}
Expand Down
26 changes: 13 additions & 13 deletions iceoryx_hoofs/vocabulary/include/iox/expected.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
namespace iox
{
template <typename T = void>
using success = detail::success<T>;
using success = detail::ok<T>;

template <typename T>
using error = detail::error<T>;
using error = detail::err<T>;

/// @brief convenience function to create an 'expected' with a 'void' value type
/// @param T helper template parameter for SFINEA
Expand All @@ -41,7 +41,7 @@ using error = detail::error<T>;
/// }
/// @endcode
template <typename T = void, typename = enable_if_void_t<T>>
detail::success<void> ok();
detail::ok<void> ok();

/// @brief convenience function to create an 'expected' with a value type by copy
/// @param T value type for the 'expected'
Expand All @@ -52,7 +52,7 @@ detail::success<void> ok();
/// }
/// @endcode
template <typename T, typename = enable_if_non_void_t<T>>
detail::success<T> ok(const T& value);
detail::ok<T> ok(const T& value);

/// @brief convenience function to create an 'expected' with a value type by move
/// @param T value type for the 'expected'
Expand All @@ -65,7 +65,7 @@ detail::success<T> ok(const T& value);
/// }
/// @endcode
template <typename T, typename = enable_if_non_void_t<T>, typename = enable_if_not_lvalue_referece_t<T>>
detail::success<T> ok(T&& value);
detail::ok<T> ok(T&& value);

/// @brief convenience function to create an 'expected' with a value type by argument forwarding
/// @param T value type for the 'expected'
Expand All @@ -76,7 +76,7 @@ detail::success<T> ok(T&& value);
/// }
/// @endcode
template <typename T, typename... Targs, typename = enable_if_non_void_t<T>>
detail::success<T> ok(Targs&&... args);
detail::ok<T> ok(Targs&&... args);

/// @brief convenience function to create an 'expected' with an error type by copy
/// @param T error type for the 'expected'
Expand All @@ -87,7 +87,7 @@ detail::success<T> ok(Targs&&... args);
/// }
/// @endcode
template <typename T>
detail::error<T> err(const T& value);
detail::err<T> err(const T& value);

/// @brief convenience function to create an 'expected' with an error type by move
/// @param T error type for the 'expected'
Expand All @@ -100,7 +100,7 @@ detail::error<T> err(const T& value);
/// }
/// @endcode
template <typename T, typename = enable_if_not_lvalue_referece_t<T>>
detail::error<T> err(T&& value);
detail::err<T> err(T&& value);

/// @brief convenience function to create an 'expected' with an error type by argument forwarding
/// @param T error type for the 'expected'
Expand All @@ -111,7 +111,7 @@ detail::error<T> err(T&& value);
/// }
/// @endcode
template <typename T, typename... Targs>
detail::error<T> err(Targs&&... args);
detail::err<T> err(Targs&&... args);

/// @brief Implementation of the C++23 expected class which can contain an error or a success value
/// @param ValueType type of the value which can be stored in the expected
Expand Down Expand Up @@ -171,7 +171,7 @@ class IOX_NO_DISCARD expected final : public FunctionalInterface<expected<ValueT
// we would like to use 'return ok(myValue)' with an implicit
// conversion to return an expected easily
// NOLINTNEXTLINE(hicpp-explicit-conversions)
expected(const detail::success<ValueType>& successValue) noexcept;
expected(const detail::ok<ValueType>& successValue) noexcept;

/// @brief constructs an expected which is signaling success and uses the value
/// provided by successValue to move construct its success value
Expand All @@ -180,7 +180,7 @@ class IOX_NO_DISCARD expected final : public FunctionalInterface<expected<ValueT
// we would like to use 'return ok(myValue)' with an implicit
// conversion to return an expected easily
// NOLINTNEXTLINE(hicpp-explicit-conversions)
expected(detail::success<ValueType>&& successValue) noexcept;
expected(detail::ok<ValueType>&& successValue) noexcept;

/// @brief constructs an expected which is signaling an error and stores the
/// error value provided by errorValue
Expand All @@ -189,7 +189,7 @@ class IOX_NO_DISCARD expected final : public FunctionalInterface<expected<ValueT
// we would like to use 'return err(myErrorValue)' with an implicit
// conversion to return an expected easily
// NOLINTNEXTLINE(hicpp-explicit-conversions)
expected(const detail::error<ErrorType>& errorValue) noexcept;
expected(const detail::err<ErrorType>& errorValue) noexcept;

/// @brief constructs an expected which is signaling an error and stores the
/// error value provided by errorValue
Expand All @@ -198,7 +198,7 @@ class IOX_NO_DISCARD expected final : public FunctionalInterface<expected<ValueT
// we would like to use 'return err(myErrorValue)' with an implicit
// conversion to return an expected easily
// NOLINTNEXTLINE(hicpp-explicit-conversions)
expected(detail::error<ErrorType>&& errorValue) noexcept;
expected(detail::err<ErrorType>&& errorValue) noexcept;

/// @brief creates an expected which is signaling success and perfectly forwards
/// the args to the constructor of ValueType
Expand Down

0 comments on commit 8ed505c

Please sign in to comment.