I
teach to use those optionals as replacements for pointers and I introduce optional before pointers as a means to return from a potentially failing function.
Don’t get me wrong, I love std::optional. But
1. Either your students already need to be familiar with the “.value()” mechanism, which implies that they understand classes,
2. Or they need to internalize “*optionalresult” which looks like a dereference but isn’t, so that’s doubly confusing if they do come from a C background.
And all of this when you’re just starting to teach parameter passing, which is where I started the discussion….
I do teach optional, even in a beginning course, but several weeks after I’ve taught them parameter passing.
Victor.