C++ – specify default value of std::function

clambda

void func(const std::function<void()>& f = empty)
{
    if(f)
        f();
}

what is the 'empty' should be? I use [](){} . But technically, that is not empty, the f() will execute.

Best Answer

void func(const std::function<void()>& f = {}) {
    if(f) f();
}

LIVE DEMO