4 ms·
> A possible std::optional footgun is that an optional object can implicitly be converted to bool, That isn't true, as std::optional are explicitly converted t
by geezerjay 8y ago
> A possible std::optional footgun is that an optional object can implicitly be converted to bool,
That isn't true, as std::optional are explicitly converted to bool to signal whether the object stores a value.
http://en.cppreference.com/w/cpp/utility/optional/operator_bool http://en.cppreference.com/w/cpp/utility/optional/operator_b...
- hoppelhase 8y agoDoes that prevent the usage shown in the blog post? std::optional<unsigned> opt = firstEvenNumberIn(text); if (opt)
- geezerjay 8y agoThat usage means "was the optional value set?" That's the whole point of an optional type, and there is absolutely no reason to prevent it.
- hoppelhase 8y agoThere is. See: https://news.ycombinator.com/item?id=17275784 https://news.ycombinator.com/item?id=17275784
- geezerjay 8y agoI've already explained why that argument makes no sense https://news.ycombinator.com/item?id=17276845 https://news.ycombinator.com/item?id=17276845
- hoppelhase 8y agoCould you elaborate more on why having the compiler tell us that we forgot to change something wouldn't be a good thing?