BOOST_HOF_STATIC_LAMBDA

Description

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

Example

#include <boost/hof.hpp>
#include <cassert>

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

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

BOOST_HOF_STATIC_LAMBDA_FUNCTION

Header

#include <boost/hof/lambda.hpp>

Description

The BOOST_HOF_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 BOOST_HOF_STATIC_LAMBDA_FUNCTION use the boost::hof::reveal adaptor to improve error messages.

Example

#include <boost/hof.hpp>
#include <cassert>

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