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.

Learn to code, grow your skills, and succeed in your tech interview

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