Showing results for 2024 - The Old New Thing

Nov 13, 2024
14
1

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