News for hackers. Stuff that matters.
Re:Modern C++ Won't Save Us by noselasd on Thursday April 25, 2019 @02:47PM (#19751296)
C++ gives you all the options as usual.

  do_stuff(my_optional.value())
Is also safe, it throws if the value is absent, the safety check is performed behind the scenes.

But people might not want to throw an exception, so

  if (my_optional) 
         do_stuff(*my_optional);
Must also be allowed. The consequence is someone can also just do

  do_stuff(*my_optional)
No safety check is done and you get undefined behavior if the value is absent.

I don't know rust so I suspect it has a language construct which c++ lacks that prevents you from doing

  let Some(obj) = my_optional 
  do_stuff(obj);
Re:Modern C++ Won't Save Us by steveklabnik on Thursday April 25, 2019 @03:53PM (#19751865)
Yes, you have to use if let, not let. That code would be a compiler error. (Specifically, a “non-exhaustive pattern” error.)