StandardCplusplus icon indicating copy to clipboard operation
StandardCplusplus copied to clipboard

functional not functional

Open Makuna opened this issue 9 years ago • 2 comments

using the latest Arduino IDE, I try to define a callback type that will be lambda compatible like...

typedef std::function<void(float progress)> AnimUpdateCallback;

and I get a compile error about std.

Makuna avatar Jun 11 '15 02:06 Makuna

@Makuna

Seems there is no std::function template in the functional file of this project.

As Vlpp library implement vl::Func (which acts like std::function) without relying on STL, it may be of use to you. I've ported it to Arduino: https://github.com/ziqin/ArdComLib/tree/lambda/Vlpp

ziqin avatar Jan 04 '16 16:01 ziqin

@ziqin

Thanks for that link. Very helpful. I created a repo with just Vlpp and set it up as a proper Adruino library. You can now pull it down as a git submodule under the libraries folder in your project.

functional-vlpp repo

I also wanted to point out that I discovered a bug in the Adruino port. vl::Func does reference counting on the object it holds. Instead of increment/decrementing the counter, the port was increment/decrementing the pointer to the counter, causing bizarre, hard to identify problems. I have fixed it in my repo.

Since my repo isn't a clone of yours, I don't think using a pull request will work well. If you're interested in the fix, please take a look at this commit.

marcusrugger avatar Apr 10 '16 16:04 marcusrugger

Sorry, functional objects came in C+11, and are not here in this library.

maniacbug avatar Jul 05 '23 23:07 maniacbug

@maniacbug What? I don't understand your comment. Std::Function objects are part of STL, not c++. Lamda support is part c++. They are two different things. Using Lamda is improved/made easier using functional. But as stated above, it is missing from "functional" header file (part of stl).

Makuna avatar Jul 05 '23 23:07 Makuna