XTE_LIFT()

Defined in header <xte/preproc/lift.hpp>

Wraps something callable in a lambda object. Automatically includes a noexcept specifier and a requires clause.


Definitions

#lift
#define XTE_LIFT(...)               \
	[](auto&&... /* args */) static \
	XTE_ARROW(__VA_ARGS__(XTE_FWD(/* args */)...))
Wraps a callable which accepts any number of arguments.

#unary
#define XTE_LIFT_UNARY(...)     \
	[](auto&& /* arg */) static \
	XTE_ARROW(__VA_ARGS__(XTE_FWD(/* arg */)))
Wraps a callable which only accepts one argument (e.g. static_cast).

#local
#define XTE_LIFT_LOCAL(...)   \
	[&](auto&&... /* args */) \
	XTE_ARROW(__VA_ARGS__(XTE_FWD(/* args */)...))
Wraps a callable which depends on local variables.

#infix
#define XTE_LIFT_INFIX(...)                       \
	[](auto&& /* lhs */, auto&& /* rhs */) static \
	XTE_ARROW(XTE_FWD(/* lhs */) __VA_ARGS__ (XTE_FWD(/* rhs */)))
Wraps a binary operator (e.g. +).

#member-func
#define XTE_LIFT_MEMBER(...)                          \
	[](auto&& /* obj */, auto&&... /* args */) static \
	XTE_ARROW(XTE_FWD(/* obj */)__VA_ARGS__(XTE_FWD(/* args */)...))
Wraps a member function, prefixed with . or ->.

#member-var
#define XTE_LIFT_VAR(...)                \
	[](auto&& /* obj */) static noexcept \
	{ return XTE_FWD(/* obj */)__VA_ARGS__; }
Wraps a member variable, prefixed with . or ->.



Example

template<typename T>
void templated(T _arg) {
	std::println("{}", _arg);
}

void call(auto func) {
	func(5);
}

call(XTE_LIFT(templated));
Output:
5
[View in Compiler Explorer]