17 #ifndef IOX_UTILS_CXX_OPTIONAL_HPP
18 #define IOX_UTILS_CXX_OPTIONAL_HPP
20 #include "iceoryx_utils/cxx/function_ref.hpp"
21 #include "iceoryx_utils/cxx/helplets.hpp"
22 #include "iceoryx_utils/cxx/types.hpp"
139 template <
typename U = T>
168 constexpr
explicit operator bool()
const noexcept;
172 constexpr
bool has_value()
const noexcept;
180 template <
typename... Targs>
181 T&
emplace(Targs&&... args) noexcept;
186 void reset() noexcept;
216 template <typename U>
217 constexpr T
value_or(U&& default_value) const noexcept;
242 alignas(T) byte_t m_data[sizeof(T)];
243 bool m_hasValue{
false};
246 template <
typename... Targs>
247 void construct_value(Targs&&... args) noexcept;
248 void destruct_value() noexcept;
256 template <typename OptionalBaseType, typename... Targs>
257 optional<OptionalBaseType> make_optional(Targs&&... args) noexcept;
261 #include "iceoryx_utils/internal/cxx/optional.inl"
Definition: function_ref.hpp:32
Optional implementation from the C++17 standard with C++11. The interface is analog to the C++17 stan...
Definition: optional.hpp:63
T & emplace(Targs &&... args) noexcept
A new element is constructed by forwarding the arguments to the constructor of T. If the optional has...
Definition: optional.inl:205
optional & operator=(const optional &rhs) noexcept
Copies an optional. If the optional has a value then the copy assignment of that value is called....
Definition: optional.inl:67
constexpr bool operator!=(const optional< T > &rhs) const noexcept
If the optionals have values it compares these values by using their comparision operator.
Definition: optional.inl:162
T & value() &noexcept
Returns a reference to the underlying value. If the optional has no value the application terminates....
void reset() noexcept
Calls the destructor of T if the optional has a value. If the optional has no value,...
Definition: optional.inl:223
const T & operator*() const noexcept
Returns a reference to the underlying value. If the optional has no value the behavior is undefined....
Definition: optional.inl:180
constexpr bool has_value() const noexcept
Will return true if the optional contains a value, otherwise false.
Definition: optional.inl:217
constexpr bool operator==(const optional< T > &rhs) const noexcept
If the optionals have values it compares these values by using their comparision operator.
Definition: optional.inl:150
const T & value() const &noexcept
Returns a const reference to the underlying value. If the optional has no value the application termi...
optional & and_then(const cxx::function_ref< void(T &)> &callable) noexcept
calls the provided callable with the optional value as arguments if the optional contains a value
Definition: optional.inl:290
~optional() noexcept
The destructor will call the destructor of T if a value is set.
Definition: optional.inl:113
const T * operator->() const noexcept
Returns a pointer to the underlying value. If the optional has no value the behavior is undefined....
Definition: optional.inl:174
optional & or_else(const cxx::function_ref< void()> &callable) noexcept
calls the provided callable if the optional does not contain a value
Definition: optional.inl:310
optional() noexcept
Creates an optional which has no value. If you access such an optional via .value() or the arrow oper...
Definition: optional.inl:30
constexpr T value_or(U &&default_value) const noexcept
If the optional contains a value a copy of that value is returned, otherwise the default_value is ret...
Definition: optional.inl:261
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28
Helper struct which is used to signal an empty optional. It is equivalent to no value.
Definition: optional.hpp:34