6

Both ArduinoSTL and StandardCplusplus don't support them. They implement the version that is compatible with c++03 (not c++11).

This functionality is handy when you design libraries that work with callbacks. And you do need them, if your Arduino does more than one thing simultaneously.

I tried also several other options, but none was enough. Most complete thing I found, Passing capturing lambda as function pointer, does not support plain function pointers and does not allow me to hold the function object as a member of the structure, because the type of the object depends on the lambda (not only its signature, like in std::function).

In particular, I need a functor that

  • can store both capturing lambdas and plain function wrappers
  • has a type that depends only on the signature of the function, so I can store it as a class member.
Glorfindel
  • 578
  • 1
  • 7
  • 18
Adam Ryczkowski
  • 279
  • 1
  • 5
  • 16

1 Answers1

2

We have written a solution, that we published as a Platformio library: https://github.com/fopeczek/function_objects.

Please note, that each functional object does one allocation, and those are not particularly friendly in an embedded environment. I am not even sure, that the Arduino C++ does heap deallocation, so you may be leaking resources if you create and destroy the functional objects in a loop.

Adam Ryczkowski
  • 279
  • 1
  • 5
  • 16