alpaqa
1.0.0a13
Nonconvex constrained optimization
Loading...
Searching...
No Matches
src
alpaqa
include
alpaqa
util
required-method.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <
alpaqa/util/type-erasure.hpp
>
4
#include <functional>
// std::invoke
5
6
#define ALPAQA_TE_REQUIRED_METHOD(vtable, type, member) \
7
do { \
8
static_assert( \
9
requires { &type::member; }, \
10
"Missing required method '" #type "::" #member "'"); \
11
(vtable).member = util::type_erased_wrapped<type, &type::member>(); \
12
} while (0)
13
#define ALPAQA_TE_OPTIONAL_METHOD(vtable, type, member, instance) \
14
do { \
15
if constexpr (requires { &type::member; }) { \
16
using vtable_t = std::remove_cvref_t<decltype(vtable)>; \
17
auto assign_vtable = [&] { \
18
(vtable).member = \
19
util::type_erased_wrapped<type, &type::member, \
20
const vtable_t &>(); \
21
}; \
22
if constexpr (requires { &type::provides_##member; }) { \
23
if (std::invoke(&type::provides_##member, instance)) \
24
assign_vtable(); \
25
} else { \
26
assign_vtable(); \
27
} \
28
} \
29
} while (0)
type-erasure.hpp
Generated on Mon Oct 30 2023 for alpaqa by
1.9.8