29 void (*eval_grad_g_prod)(
47 void (*eval_hess_L_prod)(
64 void (*eval_hess_ψ_prod)(
95 void (*eval_grad_f_grad_g_prod)(
142 void (*initialize_box_C)(
146 void (*initialize_box_D)(
150 void (*initialize_l1_reg)(
166 void (*cleanup)(
void *);
203 void (*eval_grad_f_prod)(
244 void (*eval_add_Q_N)(
249 void (*eval_add_R_masked)(
257 void (*eval_add_S_masked)(
265 void (*eval_add_R_prod_masked)(
275 void (*eval_add_S_prod_masked)(
293 void (*eval_constr_N)(
297 void (*eval_grad_constr_prod)(
303 void (*eval_grad_constr_prod_N)(
308 void (*eval_add_gn_hess_constr)(
314 void (*eval_add_gn_hess_constr_N)(
328 void (*cleanup)(
void *);
337#if defined(__cplusplus) && __cplusplus > 201703L
345 std::map<std::string, std::any>
dict{};
362 if (extra_functions ==
nullptr)
364 extra_functions->
dict.insert_or_assign(
365 std::move(name), std::function{std::forward<Func>(func)});
372 std::forward<Func>(func));
379 std::forward<Func>(func));
382template <
class Result,
class T,
class Ret,
class... Args>
384 Ret (T::*member)(Args...)) {
386 [member](
void *self_, Args... args) -> Ret {
387 auto *self = reinterpret_cast<T *>(self_);
388 return (self->*member)(std::forward<Args>(args)...);
392template <
class Result,
class T,
class Ret,
class... Args>
394 Ret (T::*member)(Args...)
const) {
396 [member](
const void *self_, Args... args) -> Ret {
397 const auto *self = reinterpret_cast<const T *>(self_);
398 return (self->*member)(std::forward<Args>(args)...);
403template <
auto Member,
class Class,
class Ret,
class... Args>
405 return [](
void *self_, Args... args) -> Ret {
406 auto *self =
reinterpret_cast<Class *
>(self_);
407 return (self->*Member)(std::forward<Args>(args)...);
411template <
auto Member,
class Class,
class Ret,
class... Args>
413 return []<
class Self>(Self * self_, Args... args) -> Ret
414 requires std::is_void_v<Self>
416 const auto *self =
reinterpret_cast<const Class *
>(self_);
417 return (self->*Member)(std::forward<Args>(args)...);
421template <auto Member,
class Class,
class Ret>
423 return []<
class Self>(Self * self_) ->
decltype(
auto)
424 requires std::is_void_v<Self>
426 using CClass = std::conditional_t<std::is_const_v<Self>,
427 std::add_const_t<Class>, Class>;
428 auto *self =
reinterpret_cast<CClass *
>(self_);
429 return self->*Member;
441template <auto Member>
443 return detail::member_caller<Member>(Member);
454 delete extra_functions;
struct alpaqa_function_dict_s alpaqa_function_dict_t
Opaque type for a C++-only map of extra functions.
ptrdiff_t alpaqa_length_t
alpaqa_length_t alpaqa_index_t
std::map< std::string, std::any > dict
void unregister_functions(function_dict_t *&extra_functions)
Cleans up the extra functions registered by register_function.
void register_function(function_dict_t *&extra_functions, std::string name, Func &&func)
Make the given function available to alpaqa.
void register_member_function(Result &result, std::string name, Ret(T::*member)(Args...))
static auto member_caller()
Wrap the given member function of signature into a lambda function that accepts the instance as a voi...
alpaqa_function_dict_t * extra_functions
Pointer to a map of extra functions (C++ only).
alpaqa_control_problem_functions_t * functions
Non-owning pointer, lifetime at least as long as instance.
void * instance
Owning pointer.
alpaqa_function_dict_t * extra_functions
Pointer to a map of extra functions (C++ only).
void * instance
Owning pointer.
alpaqa_problem_functions_t * functions
Non-owning pointer, lifetime at least as long as instance.