FIT_STATIC_LAMBDA

Description

The FIT_STATIC_LAMBDA macro allows initializing non-capturing lambdas at compile-time in a constexpr expression.

Example

#include <fit.hpp>
#include <cassert>

const constexpr auto add_one = FIT_STATIC_LAMBDA(int x)
{
    return x + 1;
};

int main() {
    assert(3 == add_one(2));
}

FIT_STATIC_LAMBDA_FUNCTION

Header

#include <fit/lambda.hpp>

Description

The FIT_STATIC_LAMBDA_FUNCTION macro allows initializing a global function object that contains non-capturing lambdas. It also ensures that the global function object has a unique address across translation units. This helps prevent possible ODR-violations.

By default, all functions defined with FIT_STATIC_LAMBDA_FUNCTION use the fit::reveal adaptor to improve error messages.

Example

#include <fit.hpp>
#include <cassert>

FIT_STATIC_LAMBDA_FUNCTION(add_one) = [](int x)
{
    return x + 1;
};
int main() {
    assert(3 == add_one(2));
}