17#ifndef IOX_HOOFS_CXX_EXPECTED_HPP
18#define IOX_HOOFS_CXX_EXPECTED_HPP
20#include "iceoryx_hoofs/cxx/attributes.hpp"
21#include "iceoryx_hoofs/cxx/function_ref.hpp"
22#include "iceoryx_hoofs/cxx/helplets.hpp"
23#include "iceoryx_hoofs/cxx/optional.hpp"
24#include "iceoryx_hoofs/cxx/variant.hpp"
47template <
typename T =
void>
59 template <
typename... Targs>
107 template <
typename... Targs>
113template <
typename... T>
114class IOX_NO_DISCARD expected;
145template <
typename ErrorType>
164 template <
typename ValueType>
169 template <
typename ValueType>
187 template <
typename ValueType>
192 template <
typename ValueType>
218 template <typename... Targs>
223 explicit operator
bool() const noexcept;
292 static constexpr uint64_t ERROR_INDEX = 0U;
298template <typename ValueType, typename ErrorType>
350 template <typename... Targs>
357 template <typename... Targs>
362 explicit operator
bool() const noexcept;
391 const ValueType&
value() const& noexcept;
418 ValueType& operator*() noexcept;
429 const ValueType& operator*() const noexcept;
438 ValueType* operator->() noexcept;
447 const ValueType* operator->() const noexcept;
460 template <typename T>
474 template <typename T>
532 template <typename Optional = ValueType,
533 typename std::enable_if<internal::IsOptional<Optional>::
value,
int>::type = 0>
547 template <typename Optional = ValueType,
548 typename std::enable_if<internal::IsOptional<Optional>::
value,
int>::type = 0>
564 template <typename Optional = ValueType,
565 typename std::enable_if<internal::IsOptional<Optional>::
value,
int>::type = 0>
581 template <typename Optional = ValueType,
582 typename std::enable_if<internal::IsOptional<Optional>::
value,
int>::type = 0>
585 optional<ValueType> to_optional() const noexcept;
588 expected(
variant<ValueType, ErrorType>&& f_store, const
bool hasError) noexcept;
589 variant<ValueType, ErrorType> m_store;
591 static constexpr uint64_t VALUE_INDEX = 0U;
592 static constexpr uint64_t ERROR_INDEX = 1U;
595template <typename ErrorType>
606#include "iceoryx_hoofs/internal/cxx/expected.inl"
expected(const success< void > &successValue) noexcept
constructs an expected which is signaling success
expected(error< ErrorType > &&errorValue) noexcept
constructs an expected which is signaling an error and stores the error value provided by value
static expected create_value() noexcept
creates an expected which is signaling success
~expected() noexcept=default
calls the destructor of the success value or error value - depending on what is stored in the expecte...
ErrorType & get_error() &noexcept
returns a reference to the contained error value, if the expected does not contain an error this is u...
expected(const expected &) noexcept=default
the copy constructor calls the copy constructor of the contained success value or the error value - d...
static expected create_error(Targs &&... args) noexcept
creates an expected which is signaling an error and perfectly forwards the args to the constructor of...
expected(expected &&rhs) noexcept
the move constructor calls the move constructor of the contained success value or the error value - d...
bool has_error() const noexcept
returns true if the expected contains an error otherwise false
const expected & and_then(const cxx::function_ref< void()> &callable) const noexcept
if the expected does contain a success value the given callable is called and a reference to the expe...
const expected & or_else(const cxx::function_ref< void(ErrorType &)> &callable) const noexcept
if the expected does contain an error the given callable is called and a reference to the ErrorType i...
expected & operator=(const expected &) noexcept
calls the copy assignment operator of the contained success value or the error value - depending on w...
expected(const error< ErrorType > &errorValue) noexcept
constructs an expected which is signaling an error and stores the error value provided by errorValue
expected()=delete
default ctor is deleted since you have to clearly state if the expected contains a success value or a...
ValueType & value() &noexcept
returns a reference to the contained success value, if the expected does not contain a success value ...
const expected & and_then(const cxx::function_ref< void(ValueType &)> &callable) const noexcept
if the expected does contain a success value the given callable is called and a reference to the resu...
const expected & or_else(const cxx::function_ref< void(ErrorType &)> &callable) const noexcept
if the expected does contain an error the given callable is called and a reference to the ErrorType i...
expected(expected &&rhs) noexcept
the move constructor calls the move constructor of the contained success value or the error value - d...
expected(const expected &) noexcept=default
the copy constructor calls the copy constructor of the contained success value or the error value - d...
const expected & if_empty(const cxx::function_ref< void()> &callable) const noexcept
if the expected contains a success value and its type is an empty optional, calls the provided callab...
ErrorType & get_error() &noexcept
returns a reference to the contained error value, if the expected does not contain an error this is u...
~expected() noexcept=default
calls the destructor of the success value or error value - depending on what is stored in the expecte...
static expected create_error(Targs &&... args) noexcept
creates an expected which is signaling an error and perfectly forwards the args to the constructor of...
bool has_error() const noexcept
returns true if the expected contains an error otherwise false
expected()=delete
default ctor is deleted since you have to clearly state if the expected contains a success value or a...
ValueType value_or(const ValueType &value) const noexcept
returns a copy of the contained success value if the expected does contain a success value,...
static expected create_value(Targs &&... args) noexcept
creates an expected which is signaling success and perfectly forwards the args to the constructor of ...
Definition function_ref.hpp:34
Optional implementation from the C++17 standard with C++11. The interface is analog to the C++17 stan...
Definition optional.hpp:69
Variant implementation from the C++17 standard with C++11. The interface is inspired by the C++17 sta...
Definition variant.hpp:107
building block to easily create free function for logging in a library context
Definition lockfree_queue.hpp:29
helper struct to create an expected which is signalling an error more easily
Definition expected.hpp:92
error(T &&t) noexcept
constructor which creates a error helper class by moving the value of t
error(const T &t) noexcept
constructor which creates a error helper class by copying the value of t
error(Targs &&... args) noexcept
constructor which creates a error helper class by forwarding arguments to the constructor of T
helper struct to create an expected which is signalling success more easily
Definition expected.hpp:49
success(const T &t) noexcept
constructor which creates a success helper class by copying the value of t
success(T &&t) noexcept
constructor which creates a success helper class by moving the value of t
success(Targs &&... args) noexcept
constructor which creates a success helper class by forwarding arguments to the constructor of T