Hot answers tagged

10

The STL is not a part of Arduino IDE. Although efficient by desktop standards, the consensus is it doesn't fit comfortably in an Arduino's limited space. That said, here's someone who seems to have done it: https://github.com/maniacbug/StandardCplusplus Check out the forks, they seem more up to date


6

I maintain an Arduino plugin that's a port of uClibc++ (just like the defunct StandardCplusplus library). It's available in the Arduino library manager for Arduino versions 1.6.10 and higher. It's called ArduinoSTL.


4

STL is efficient on the platform it was designed for, which is personal computers and similar-scale devices, where allocating a single byte in the heap consumes a 4k memory page (that's several times as much as ALL Arduino RAM), and where array indexes can be efficiently replaced by pointers (8-bit microcontrollers need at least two commands to deal with a ...


3

The STL is not a part of Arduino IDE. Another answer is mentioning https://github.com/maniacbug/StandardCplusplus although this library doesn't seem to be maintained anymore. Maybe a better idea could be to try https://github.com/mike-matera/ArduinoSTL It's a port of uClibc++ packaged as an Arduino library.


3

std::array does not use dynamic memory allocations to store its elements. If you use static or stack-allocated std::arrays, you don't have to worry about memory fragmentation (contrary to std::vector or String, for example). Of course, if you allocate arrays on the stack, you can have a stack overflow if you call too many functions, either by design, or ...


2

The STL is not part of Arduino and no support for libstc++ from AVR. My "answer" differences from Malachi at one point though, as explained in the comments. I don't think you shouldn't, just because "most people say" that you shouldn't. There are a lot of people that even think you shouldn't use C++ at all. The problem is that C++ (and C++ standard library)...


2

std::function is not supported by the Arduino environment. (Edit: as mentioned by KIIV in a comment, it's supported on ARM targets, but not on AVR.) You can, however, pass a non-capturing lambda to a function that expects a plain function pointer. For example, given T reduce(const T initial, T (*acc)(T, T)) { T value = initial; for (size_t i = 0; i &...


2

The ARM gcc libraries offer a simple way to redirect standard outputs. It is enough to implement function _write(int fd, char *ptr, int len) and it will replace the default implementation used in library to direct the standard outputs to debugger semihosting. The function must be compiled as C to match. #include <Arduino.h> #undef max #undef min #...


1

I ended up just inheriting AccelStepper, and extending the AccelStepper::AccelStepper ( uint8_t interface = AccelStepper::FULL4WIRE,uint8_t pin1 = 2,uint8_t pin2 = 3, uint8_t pin3 = 4, uint8_t pin4 = 5, bool enable = true ) constructor to add my own Adafruit_StepperMotor instance variable and using it in an overridden step0 (which is the only function ...


1

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 ...


Only top voted, non community-wiki answers of a minimum length are eligible