What is the purpose of std::optional?
- A To represent a value that may or may not be present, without using a null pointer or sentinel
- B To make a type nullable at runtime
- C To optimise memory layout
- D To defer construction to another thread
Answer
To represent a value that may or may not be present, without using a null pointer or sentinel
optional expresses absence in the type system, which is clearer and safer than a magic value such as -1 or a nullable pointer.





