What the title says .
Since autumn 2021, I'm learning the c++ 20 language evolutions. Almost finished. Is anyone else into this?
What the title says .
Since autumn 2021, I'm learning the c++ 20 language evolutions. Almost finished. Is anyone else into this?
I've since completed this. Getting you riled up with some C++ constructs: two ways to loop over an array and perform an action:
definition:
#include <stdio.h> #include <algorithm> #include "pico/stdlib.h" const uint LED_G = 16; const uint LED_R = 17; const uint LED_B = 25; void initpin(uint gpio) { gpio_init(gpio); gpio_set_dir(gpio, GPIO_OUT); gpio_put(gpio, 1); } int main() { uint leds[3] = {LED_G, LED_R, LED_B};
iterating with an auto-for combo:
// for and auto for(auto n : leds){ initpin(n); }
iterating with a lamdba:
// for_each and lambda std::for_each(leds, leds + std::size(leds), [](auto n){ initpin(n); });
opinions?
I'm not sure, but since I'm only familiar with old STL, the second option looks slightly more in line with tradition. (Not that STL ever feels traditional/friendly for me unless I use it regularly).
But I can imagine for a complete newcomer learning without baggage, then the first option might be easier on the eyes.
I've no idea how it actually looks at the machine instruction level, but as we found on some other thread a while back regarding classes, C++ features can actually assemble into very efficient forms, as efficient as C code was what we found back then.