3

Consider the following four lambdas:

#include <type_traits>

const auto f1 = [](auto) mutable {};  // const, mutable, generic
const auto f2 = [](auto) {};          // const,          generic
const auto f3 = [](int)  mutable {};  // const, mutable
auto f4 = [](auto) mutable {};        //        mutable, generic

static_assert(std::is_invocable_v<decltype(f1), int>); // failed
static_assert(std::is_invocable_v<decltype(f2), int>); // not mutable, okay
static_assert(std::is_invocable_v<decltype(f3), int>); // not generic, okay
static_assert(std::is_invocable_v<decltype(f4), int>); // not const, okay

int main() {}

See demo

Why aren't const, mutable, generic lambdas invocable, when any pairing of const, mutable or generic does produce an invocable lambda?

Brian61354270
  • 8,690
  • 4
  • 21
  • 43

0 Answers0