alpaqa 1.0.0a14
Nonconvex constrained optimization
Loading...
Searching...
No Matches
Macros
required-method.hpp File Reference
#include <alpaqa/util/type-erasure.hpp>
#include <functional>
+ Include dependency graph for required-method.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ALPAQA_TE_REQUIRED_METHOD(vtable, type, member)
 
#define ALPAQA_TE_OPTIONAL_METHOD(vtable, type, member, instance)
 

Macro Definition Documentation

◆ ALPAQA_TE_REQUIRED_METHOD

#define ALPAQA_TE_REQUIRED_METHOD (   vtable,
  type,
  member 
)
Value:
do { \
static_assert( \
requires { &type::member; }, \
"Missing required method '" #type "::" #member "'"); \
(vtable).member = util::type_erased_wrapped<type, &type::member>(); \
} while (0)

Definition at line 6 of file required-method.hpp.

◆ ALPAQA_TE_OPTIONAL_METHOD

#define ALPAQA_TE_OPTIONAL_METHOD (   vtable,
  type,
  member,
  instance 
)
Value:
do { \
if constexpr (requires { &type::member; }) { \
using vtable_t = std::remove_cvref_t<decltype(vtable)>; \
auto assign_vtable = [&] { \
(vtable).member = \
util::type_erased_wrapped<type, &type::member, \
const vtable_t &>(); \
}; \
if constexpr (requires { &type::provides_##member; }) { \
if (std::invoke(&type::provides_##member, instance)) \
assign_vtable(); \
} else { \
assign_vtable(); \
} \
} \
} while (0)

Definition at line 13 of file required-method.hpp.