What is the point of `std::make_optional`

One example of the difference is when you want (for whatever reason) to make an optional containing an optional: #include <optional> #include <type_traits> int main() { auto inner=std::make_optional(325); auto opt2=std::make_optional(inner); // makes std::optional<std::optional<int>> auto opt3=std::optional(inner); // just a copy of inner static_assert(std::is_same_v<decltype(opt2), std::optional<std::optional<int>>>); static_assert(std::is_same_v<decltype(opt3), std::optional<int>>); }

Why does std::optional not have a specialization for reference types?

When n3406 (revision #2 of the proposal) was discussed, some committee members were uncomfortable with optional references. In n3527 (revision #3), the authors decided to make optional references an auxiliary proposal, to increase the chances of getting optional values approved and put into what became C++14. While optional didn’t quite make it into C++14 for … Read more