Showing results for November 2024 - Page 2 of 3 - The Old New Thing

Nov 13, 2024
14
2

The puzzle of trying to put an object into a std::optional

Raymond Chen
Raymond Chen

The C++ standard library template type has one of two states. It could be empty (not contain anything), or it could contain a . Suppose you start with an empty . How do you put a into it? One of my colleagues tried to do it in what seemed to be the most natural way: Use the assignment operator. Unfortunately, the assignment failed to compile...

Code