std::optional Creation

This lesson explains the different ways of creating std::optional variables.

There are several ways to create std::optional:

  • Initialise as empty
  • Directly with a value
  • With a value using deduction guides
  • By using make_optional
  • With std::in_place
  • From other optional

See code below:

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy