16#ifndef IOX_HOOFS_CXX_FUNCTIONAL_POLICY_HPP
17#define IOX_HOOFS_CXX_FUNCTIONAL_POLICY_HPP
19#include "iceoryx_hoofs/cxx/function_ref.hpp"
20#include "iceoryx_hoofs/cxx/helplets.hpp"
30template <
typename Derived,
class =
void>
31struct HasValueMethod : std::false_type
35template <
typename Derived>
36struct HasValueMethod<Derived, cxx::void_t<decltype(std::declval<Derived>().value())>> : std::true_type
40template <
typename Derived,
class =
void>
41struct HasGetErrorMethod : std::false_type
45template <
typename Derived>
46struct HasGetErrorMethod<Derived, cxx::void_t<decltype(std::declval<Derived>().get_error())>> : std::true_type
50template <
typename Derived>
56 void expect(
const char*
const msg)
const noexcept;
59template <
typename Derived,
typename ValueType>
66 ValueType& expect(
const char*
const msg) &
noexcept;
72 const ValueType& expect(
const char*
const msg)
const&
noexcept;
78 ValueType&& expect(
const char*
const msg) &&
noexcept;
84 const ValueType&& expect(
const char*
const msg)
const&&
noexcept;
87template <
typename Derived,
typename ValueType>
97 ValueType value_or(U&& alternative)
const&
noexcept;
105 template <
typename U>
106 ValueType value_or(U&& alternative) &&
noexcept;
109template <
typename Derived,
typename ValueType>
110struct AndThenWithValue
112 using and_then_callback_t = cxx::function_ref<void(ValueType&)>;
113 using const_and_then_callback_t = cxx::function_ref<void(
const ValueType&)>;
120 Derived& and_then(
const and_then_callback_t& callable) &
noexcept;
127 const Derived& and_then(
const const_and_then_callback_t& callable)
const&
noexcept;
134 Derived&& and_then(
const and_then_callback_t& callable) &&
noexcept;
141 const Derived&& and_then(
const const_and_then_callback_t& callable)
const&&
noexcept;
144template <
typename Derived>
147 using and_then_callback_t = cxx::function_ref<void()>;
153 Derived& and_then(
const and_then_callback_t& callable) &
noexcept;
159 const Derived& and_then(
const and_then_callback_t& callable)
const&
noexcept;
165 Derived&& and_then(
const and_then_callback_t& callable) &&
noexcept;
171 const Derived&& and_then(
const and_then_callback_t& callable)
const&&
noexcept;
174template <
typename Derived,
typename ErrorType>
175struct OrElseWithValue
177 using or_else_callback_t = cxx::function_ref<void(ErrorType&)>;
178 using const_or_else_callback_t = cxx::function_ref<void(
const ErrorType&)>;
185 Derived& or_else(
const or_else_callback_t& callable) &
noexcept;
192 const Derived& or_else(
const const_or_else_callback_t& callable)
const&
noexcept;
199 Derived&& or_else(
const or_else_callback_t& callable) &&
noexcept;
206 const Derived&& or_else(
const const_or_else_callback_t& callable)
const&&
noexcept;
209template <
typename Derived>
212 using or_else_callback_t = cxx::function_ref<void()>;
218 Derived& or_else(
const or_else_callback_t& callable) &
noexcept;
224 const Derived& or_else(
const or_else_callback_t& callable)
const&
noexcept;
230 Derived&& or_else(
const or_else_callback_t& callable) &&
noexcept;
236 const Derived&& or_else(
const or_else_callback_t& callable)
const&&
noexcept;
239template <
typename Derived,
typename ValueType,
typename ErrorType>
240struct FunctionalInterfaceImpl :
public ExpectWithValue<Derived, ValueType>,
241 public ValueOr<Derived, ValueType>,
242 public AndThenWithValue<Derived, ValueType>,
243 public OrElseWithValue<Derived, ErrorType>
247template <
typename Derived>
248struct FunctionalInterfaceImpl<Derived, void, void>
249 :
public Expect<Derived>,
public AndThen<Derived>,
public OrElse<Derived>
253template <
typename Derived,
typename ValueType>
254struct FunctionalInterfaceImpl<Derived, ValueType, void> :
public ExpectWithValue<Derived, ValueType>,
255 public ValueOr<Derived, ValueType>,
256 public AndThenWithValue<Derived, ValueType>,
257 public OrElse<Derived>
261template <
typename Derived,
typename ErrorType>
262struct FunctionalInterfaceImpl<Derived, void, ErrorType>
263 :
public Expect<Derived>,
public AndThen<Derived>,
public OrElseWithValue<Derived, ErrorType>
283template <
typename Derived,
typename ValueType,
typename ErrorType>
284using FunctionalInterface = internal::FunctionalInterfaceImpl<Derived, ValueType, ErrorType>;
289#include "iceoryx_hoofs/internal/cxx/functional_interface.inl"
building block to easily create free function for logging in a library context
Definition lockfree_queue.hpp:29