C++ — Why can’t a const mutable lambda with an auto& parameter be invoked?

#include <type_traits>

int main()
{
auto f1 = [](auto&) mutable {};
static_assert(std::is_invocable_v<decltype(f1), int&>); // ok

auto const f2 = [](auto&) {};
static_assert(std::is_invocable_v<decltype(f2), int&>); // ok

auto const f3 = [](auto&) mutable {};
static_assert(std::is_invocable_v<decltype(f3), int&>); // failed
}

--

--

--

Flutter and Native Android developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to create ReactJS project using Vite

AppScript — get user profile picture without using Admin APIs

Learn RxJS fromEvent,scan and reduce operator

20220318

Package.json vs Package-lock.json

Sorting Code Challenge Breakdown

A representative from Friends of Surely holds up a giant check for five hundred dollars for Surely Fünke for life.

webpack-dev-server returns 400 error for all request

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Flutter Developer

Flutter Developer

Flutter and Native Android developer

More from Medium

Deep deep deep into Promises

Building an API in C++ With Pistache

JavaScript’s Document Object Model (DOM)

AJ Auntor

Getting Started with WebSockets in F#