Vrekrer / Vrekrer_scpi_parser

Simple SCPI parser for Arduino
MIT License
87 stars 26 forks source link

Use std::function #23

Closed Xerbo closed 1 year ago

Xerbo commented 2 years ago

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.

Vrekrer commented 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?

Xerbo commented 1 year ago

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.