Free Arduino library BasicOptional tutorial @resonance2001
Free Arduino library BasicOptional tutorial  @resonance2001
Uploaded November 2020 | Updated September 2026, 2 weeks ago
I have written a version of std::optional called BasicOptional for the Arduino and I'm giving it away. If you want the library, here is a link:

https://1drv.ms/u/s!AoticBc4xuQQgTdegDKG5Aen2QW-?e=5DFcXg

My version implements some of the functions used on the 'optional' standard library in C++ but I may come back to this and expand upon it.
This is useful for functions that can either return something or fail to for example, you could have a function that converts string to a number. If the string is corrupted, it could return a 0 or a -1 but these are also valid numbers that could be in the string so what can we do in this scenario?
The Arduino does not have exception handling so an error cannot be reported. What you can do is return a ‘BasicOptional’ which contains the number or it is empty. You can run code if a number is contained within or you could supply your own default number if the function couldn’t decode the string.

The ‘optional’ class is used in C++17.
Free Arduino library BasicOptional tutorialTV appearance BBC Dave Gorman Genius behind the scenesFree Arduino library StackStringFrench future tense patterns of conjugation tutorialSteampunk proximity sensorDangerous lorry with doors open dash camCenter Parcs Zip line Aerial AdventureInvunrable to fireEarly test of the gremlinSkiing fast to the tunnel pnp pov2nd Steampunk interview Lincoln AsylumTest of the head of the robot dog
resonance2001 |

Free Arduino library BasicOptional tutorial

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER