0

I'm not exactly new to C++ but this is the first time I've stumbled accross a notation that goes like this:

/*handling uploading firmware file */
  server.on("/update", HTTP_POST, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/plain", (Update.hasError()) ? "FAIL" : "OK");
    ESP.restart();
  },
[parameter list goes on..]

Explanation: This code is built for an esp32 microcontroller. The particular code snipplet deals with listening to HTTP_POST requests, which will be pushing an "update" button on a served web page. A library "Update.h" is used in which a class "Update" is instantiated.

But I'm now confused about the {} parameter thingy. What is this? I've never come accross this and don't know what i should make of it..?

glades
  • 169
  • 1
  • 7
  • This []() {} means the same as []{}.:) – Vlad from Moscow Nov 04 '20 at 15:48
  • 2
    It's a [lambda expression](https://en.cppreference.com/w/cpp/language/lambda) - i.e. an anonymous function, which, in this case, is being passed as a parameter to `server.on`. – Paul Sanders Nov 04 '20 at 16:03
  • Why do people downvote this? This is a valid question IMO and is well written. How is OP supposed to research lambda expressions if he doesn't know about them in the first place? He can't exactly type in "What is this [](){} thingy" into google, can he? It's understandable that not everybody is up to date with every recent development of the standard, especially for people comming back after some years and who still did 03. – Sebastian Hoffmann Nov 04 '20 at 16:35

0 Answers0