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"
30 template <
typename Derived,
class =
void>
31 struct HasValueMethod : std::false_type
35 template <
typename Derived>
36 struct HasValueMethod<Derived, cxx::void_t<decltype(std::declval<Derived>().value())>> : std::true_type
40 template <
typename Derived,
class =
void>
41 struct HasGetErrorMethod : std::false_type
45 template <
typename Derived>
46 struct HasGetErrorMethod<Derived, cxx::void_t<decltype(std::declval<Derived>().get_error())>> : std::true_type
50 template <
typename Derived>
56 void expect(
const char*
const msg)
const noexcept;
59 template <
typename Derived,
typename ValueType>
60 struct ExpectWithValue
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;
87 template <
typename Derived,
typename ValueType>
97 ValueType value_or(U&& alternative)
const& noexcept;
105 template <
typename U>
106 ValueType value_or(U&& alternative) && noexcept;
109 template <
typename Derived,
typename ValueType>
110 struct 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;
144 template <
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;
174 template <
typename Derived,
typename ErrorType>
175 struct 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;
209 template <
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;
239 template <
typename Derived,
typename ValueType,
typename ErrorType>
240 struct FunctionalInterfaceImpl :
public ExpectWithValue<Derived, ValueType>,
241 public ValueOr<Derived, ValueType>,
242 public AndThenWithValue<Derived, ValueType>,
243 public OrElseWithValue<Derived, ErrorType>
247 template <
typename Derived>
248 struct FunctionalInterfaceImpl<Derived, void, void>
249 :
public Expect<Derived>,
public AndThen<Derived>,
public OrElse<Derived>
253 template <
typename Derived,
typename ValueType>
254 struct FunctionalInterfaceImpl<Derived, ValueType, void> :
public ExpectWithValue<Derived, ValueType>,
255 public ValueOr<Derived, ValueType>,
256 public AndThenWithValue<Derived, ValueType>,
257 public OrElse<Derived>
261 template <
typename Derived,
typename ErrorType>
262 struct FunctionalInterfaceImpl<Derived, void, ErrorType>
263 :
public Expect<Derived>,
public AndThen<Derived>,
public OrElseWithValue<Derived, ErrorType>
283 template <
typename Derived,
typename ValueType,
typename ErrorType>
284 using 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