13#ifndef IOX2_INCLUDE_GUARD_BB_STL_EXPECTED_HPP
14#define IOX2_INCLUDE_GUARD_BB_STL_EXPECTED_HPP
45 template <
typename Err = E>
48 : m_error(std::forward<Err>(
err)) {
51 template <
class... Args>
53 : m_error(std::forward<Args>(args)...) {
56 constexpr auto error() &
noexcept -> E& {
60 constexpr auto error() const& noexcept -> const E& {
64 constexpr auto error() &&
noexcept -> E&& {
65 return std::move(m_error);
68 constexpr auto error() const&& noexcept -> const E&& {
69 return std::move(m_error);
73#if __cplusplus >= 201703L
78template <
typename T,
typename E>
86 : m_value(
iox2::legacy::in_place) {
90 typename V = std::remove_cv_t<T>,
91 std::enable_if_t<std::is_convertible<U, V>::value && std::is_same<U, V>::value,
bool> =
true>
94 : m_value(
iox2::legacy::in_place_t {}, std::forward<U>(value)) {
98 typename V = std::remove_cv_t<T>,
99 std::enable_if_t<std::is_convertible<U, V>::value && !std::is_same<U, V>::value,
bool> =
true>
101 : m_value(
iox2::legacy::in_place_t {}, std::forward<U>(value)) {
106 : m_value(
iox2::legacy::unexpect_t {}, error.error()) {
111 : m_value(
iox2::legacy::unexpect_t {}, std::forward<E>(error.error())) {
114 template <
typename... Args>
117 : m_value(
iox2::legacy::in_place_t {}, std::forward<Args>(args)...) {
120 template <
typename... Args>
123 : m_value(
iox2::legacy::unexpect_t {}, std::forward<Args>(args)...) {
140 constexpr explicit operator bool() const noexcept {
145 template <typename U = T, std::enable_if_t<std::is_void<U>::value,
bool> =
true>
146 constexpr auto value() const& noexcept ->
void {
149 template <typename U = T, std::enable_if_t<std::is_void<U>::value,
bool> =
true>
150 constexpr auto value() &&
noexcept ->
void {
153 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
155 return m_value.
value(location);
158 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
161 return m_value.
value(location);
164 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
167 return std::move(m_value).value(location);
170 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
173 return std::move(m_value).value(location);
178 template <typename U = T, std::enable_if_t<std::is_void<U>::value,
bool> =
true>
182 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
187 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
188 constexpr auto operator*() const& noexcept -> const U& {
192 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
194 return std::move(*this).value();
197 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
198 constexpr auto operator*() const&& noexcept -> const U&& {
199 return std::move(*this).value();
204 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
209 template <typename U = T, std::enable_if_t<!std::is_void<U>::value,
bool> =
true>
217 return m_value.
error(location);
222 return m_value.
error(location);
227 return std::move(m_value).error(location);
232 return std::move(m_value).error(location);
#define IOX2_NO_DISCARD
IOX2_NO_DISCARD adds the [[nodiscard]] keyword if it is available for the current compiler.
constexpr auto operator*() &noexcept -> U &
constexpr Expected(const Expected &)=default
constexpr auto operator=(Expected &&rhs) noexcept -> Expected &=default
constexpr Expected(Expected &&rhs) noexcept=default
constexpr Expected(const Unexpected< E > &error)
constexpr Expected(UnexpectT, Args &&... args)
constexpr Expected(Unexpected< E > &&error)
constexpr auto error(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &noexcept -> E &
constexpr auto operator->() noexcept -> U *
constexpr auto operator*() const &noexcept -> const U &
constexpr auto operator*() const noexcept -> U
constexpr auto value(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) const &noexcept -> const U &
constexpr auto value(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &&noexcept -> U &&
constexpr auto error(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) const &noexcept -> const E &
constexpr auto operator*() const &&noexcept -> const U &&
constexpr auto operator=(const Expected &) -> Expected &=default
constexpr auto operator->() const noexcept -> const U *
constexpr auto value() const &noexcept -> void
constexpr auto error(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &&noexcept -> E &&
constexpr auto value() &&noexcept -> void
constexpr Expected(InPlaceT, Args &&... args)
constexpr auto error(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) const &&noexcept -> const E &&
constexpr Expected(U &&value)
constexpr auto value(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &noexcept -> U &
constexpr auto value(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) const &&noexcept -> const U &&
constexpr auto has_value() const noexcept -> bool
constexpr auto operator*() &&noexcept -> U &&
constexpr auto error() &&noexcept -> E &&
constexpr auto error() const &noexcept -> const E &
constexpr Unexpected(const Unexpected &)=default
auto operator=(const Unexpected &) -> Unexpected &=default
constexpr Unexpected(Err &&err)
auto operator=(Unexpected &&) -> Unexpected &=default
constexpr Unexpected(InPlaceT, Args &&... args)
constexpr auto error() &noexcept -> E &
constexpr auto error() const &&noexcept -> const E &&
constexpr Unexpected(Unexpected &&)=default
Implementation of the C++23 expected class which can contain an error or a success value.
enable_if_non_void_t< U > & value(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &noexcept
returns a lvalue reference to the contained success value, if the expected does not contain a success...
bool has_value() const noexcept
returns true if the expected contains a value type and false if it is an error type
ErrorType & error(bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &noexcept
returns a lvalue reference to the contained error value, if the expected does not contain an error th...
constexpr InPlaceT IN_PLACE
constexpr UnexpectT UNEXPECT
iox2::bb::variation::Unexpected< E > Unexpected
constexpr auto err(const E &error) -> Unexpected< E >