C++26: range support for std::optional
I learned about the new range API of std::optional from Steve Downey at CppCon 2025 during his talk about std::optional<T&>. To be honest, I found the idea quite strange at first. I wanted to dig deeper to understand the motivation and the implications.The first example I encountered was this:1
2
3
4
5
6
7
void doSomething(std::string const& data,
std::optional<Logger&> logger = {}) {
for (auto l : logger) {
l.log(data);
}
return;
}
This shows that you can iterate over an optional. In fact, iter...
Read more at sandordargo.com