Closed Xerbo closed 1 year ago
Hello. Thanks for the contribution, and sorry for the late reply.
Unfortunately, std::function
is not supported by the Arduino IDE compiler.
See: Is there any working analogue to the pair std::function and std::bind in Arduino?
That's annoying, was working fine for me in PlatformIO. I suppose an #ifdef
could be used, for example:
#ifdef USE_STD_FUNCTION
# ifdef IS_PLATFORM_IO
# define _USE_STD_FUNCTION
# else
# error "Cannot use std::function with Arduino IDE"
# endif
#endif
#ifdef _USE_STD_FUNCTION
// std::function code
#else
// function pointer code
#endif
But as far as I can tell PlatformIO doesn't define any macros to identify itself.
Using std::function allows callbacks to be passed as lambda functions and thus avoids polluting the global scope.
This is fully backwards compatible with existing code.